UISlider, UISlider

Source: Internet
Author: User

UISlider, UISlider

// Create UISlider. The height is a value, but cannot be set to 0.

// Slide if the height is 0

UISlider * slider = [[UISlideralloc] initWithFrame: CGRectMake (200, 10)];


// Set the maximum value. Do not set the inverse value. Otherwise, you cannot slide.

Slider. maximumValue = 1;

Slider. minimumValue = 0;

// Set the initial value of the row.

Slider. value =. 5;

// [Slider setValue:. 5 animated: YES];

// Create an image that needs to be displayed on the sliding button

UIImage * img1 = [UIImageimageNamed: @ "com_thumb_max_n-Decoded"];

UIImage * img2 = [UIImageimageNamed: @ "com_thumb_max_h-Decoded"];

// Set the image of the sliding button

[Slider setThumbImage: img1forState: UIControlStateNormal];

[Slider setThumbImage: img2forState: UIControlStateHighlighted];


UIImage * sliderImg1 = [UIImageimageNamed: @ "com_slider_min_l-Decoded"];

UIImage * sliderImg2 = [UIImageimageNamed: @ "com_slider_max_l-Decoded"];

// Set the stretch point (------ key ------)

SliderImg1 = [sliderImg1 stretchableImageWithLeftCapWidth: 10 topCapHeight: 0];

SliderImg2 = [sliderImg2 stretchableImageWithLeftCapWidth: 10 topCapHeight: 0];

// Set the picture displayed by the row

[Slider setMinimumTrackImage: sliderImg1forState: UIControlStateNormal];

[Slider setMaximumTrackImage: sliderImg2forState: UIControlStateNormal];

// Set the color of the row.

// [Slider setMinimumTrackTintColor: [UIColor redColor];

// [Slider setMaximumTrackTintColor: [UIColor greenColor];

// Add a slide event

[Slider addTarget: selfaction: @ selector (sliderAction :) forControlEvents: UIControlEventValueChanged];

[_ Window addSubview: slider];

/* ------------------------ Use of UISwitch ----------------------*/

// Fixed in width and height

UISwitch * swithch = [[UISwitchalloc] initWithFrame: CGRectMake (90,90, 0, 0)];

// Set the status of the switch. The switch is disabled by default.

// Swithch. on = YES;

[Swithch setOn: YESanimated: YES];

[Swithch addTarget: selfaction: @ selector (switchAction :) forControlEvents: UIControlEventValueChanged];

[_ Window addSubview: swithch];

Return YES;

}



-(Void) sliderAction :( UISlider *) slider {


NSLog (@ "slider: %. 2f", slider. value );


}


-(Void) switchAction :( UISwitch *) sw {


If (sw. on = YES ){

NSLog (@ "enabled ");

} Else {

NSLog (@ "off ");

}

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.