[IOS development-11] describes the attributes of UISlider slide and displays change values in real time when tags are used together. iosuislider

Source: Internet
Author: User

[IOS development-11] describes the attributes of UISlider slide and displays change values in real time when tags are used together. iosuislider

(1) You can set an image on the next page of the previous page on the left and right sides of the slide bar;


(2) Slide Track images can be set as gradient images.


(3) because the sliding bar can interact with values, addTarget: The method is very important. The change of the event value UIControlEventValueChanged is special. In fact, it is an event only when the button is pressed.


# Import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController {// should be followed by getValue: The method must call this object, so you have to make it a global variable UILabel * label1;}-(void) viewDidLoad {// instantiate a slide bar UISlider * sli1 = [[UISlider alloc] init]; // you can specify the widget position and size without affecting the widget size, however, when the height is set to 0, the slider cannot be dragged to sli1.frame = CGRectMake (30, 30,300, 60); // set the value to sli1.value = 0.8; // set the minimum value to sli1.minimumValue = 1; // set the maximum value of sli1.maximumValue = 10; // you can specify the slider color sli1.minimumTrackTintColor = [UIColor redColor]. // you can specify the slider color sli1.maximumTrackTintColor = [UIColor blackColor]. // if you set the minimum value to one end of the image, the sliding bar width will be squashed. sli1.minimumValueImage = [UIImage imageNamed: @ "1.png"]; // if you set the maximum value to one end, the sliding bar width will be squashed: @ "2.png"]; // set the slider color. It seems to be invalid. It may be the default image, and the color sli1.thumbTintColor = [UIColor yellowColor] has been overwritten. // set the background image that has been slide over one end to overwrite the previous color. The following is the same [sli1 setMinimumTrackImage: [UIImage imageNamed: @ "3.png"] forState: UIControlStateNormal]; // set the background image of the slide bar without passing through the image [sli1 setMaximumTrackImage: [UIImage imageNamed: @ "logo.png"] forState: UIControlStateNormal]; // set the background of the slider image [sli1 setThumbImage: [UIImage imageNamed: @ "1.png"] forState: UIControlStateNormal]; // The most important thing is to perform operations based on the sliding event. // similar to the button, however, the button event is pressed, and the event here is a change in the value of UIControlEventValueChanged is the event [sli1 addTarget: self action: @ selector (getValue1 :) forControlEvents: UIControlEventValueChanged]; // set a tag, display the changed value in real time // make it a global variable, so here it is not UILabel * label1, And you can directly initialize label1 = [[UILabel alloc] initWithFrame: CGRectMake (30,100,300, 50)]; label1.text = @ "value"; [self. view addSubview: sli1]; [self. view addSubview: label1]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} -(void) getValue1 :( id) sender {UISlider * sli2 = (UISlider *) sender; label1.text = [NSString stringWithFormat: @ "% f", sli2.value];} @ end



IOS Development: A UISlider Frame correctly displayed in the middle of the screen

Isn't the center attribute of the user UISlider enough?


Related Article

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.