IOS stage study 34th days notes (UI widget UISegment-UISlider-UIStepper-UIProgressView-UITextView Introduction), uiprogressview
IOS Learning (UI) knowledge point sorting
I. UI Widgets
1. UISegmentedControl multipart selector instance code
1-(void) viewDidLoad {2 [super viewDidLoad]; 3 // segment selector 4 // In iOS6, the width of each segment is determined based on the number of words 5 // After iOS7, the width of each segment is the same, and the width depends on the maximum number of words 6 self. view. backgroundColor = [UIColor whiteColor]; 7 seg = [[UISegmentedControl alloc] initWithItems: @ [@ "message", @ "Video Phone"]; 8 self. navigationItem. titleView = seg; 9 // set a selected option 10 seg. selectedSegmentIndex = 1; 11 12 UIButton * button = [[UIButton alloc] init]; 13 button. frame = CGRectMake (80,100,200, 30); 14 button. backgroundColor = [UIColor blackColor]; 15 [button setTitle: @ "add" forState: UIControlStateNormal]; 16 [button setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; 17 [button addTarget: self action: @ selector (touchButton :) forControlEvents: UIControlEventTouchUpInside]; 18 19 [self. view addSubview: button]; 20 UIButton * rmbutton = [[UIButton alloc] init]; 21 rmbutton. frame = CGRectMake (80,200,200, 30); 22 rmbutton. backgroundColor = [UIColor blackColor]; 23 [rmbutton setTitle: @ "Remove" forState: Unknown]; 24 [rmbutton setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; 25 [rmbutton addTarget: self action: @ selector (touchRmButton :) forControlEvents: UIControlEventTouchUpInside]; 26 [self. view addSubview: rmbutton]; 27 // Add a click event listener to the seg 28 [seg addTarget: self action: @ selector (changeView :) forControlEvents: UIControlEventValueChanged]; 29} 30 31 // insert a 32-(void) touchButton (UIButton *) button {33 // [seg insertSegmentWithTitle: button. titleLabel. text atIndex: 2 animated: YES]; 34 [seg insertSegmentWithImage: [UIImage imageNamed: @ "005"] atIndex: 2 animated: YES]; 35 36} 37 // remove a segment38-(void) touchRmButton :( UIButton *) button {39 [seg removeSegmentAtIndex: 1 animated: YES]; 40} 41 // Click Event 42-(void) changeView :( UISegmentedControl *) mseg {43 NSLog (@ "% li", mseg. selectedSegmentIndex); 44}
As follows:
2. UISlider slider instance code
1-(void) viewDidLoad {2 [super viewDidLoad]; 3 // The specified height is invalid. 4 UISlider * slider = [[UISlider alloc] initWithFrame: CGRectMake (10,100,300,200)]; 5 [self. view addSubview: slider]; 6 // the maximum value of the slider is 7 slider. maximumValue = 1.0; 8 // the minimum value of the slider is 9 slider. minimumValue = 0.0; 10 // the current value of the slider is 11 slider. value = 0.1; 12 // continuous: NO: The method is not responded during the sliding process. The corresponding event Method 13 slider is called only when the sliding is stopped. continuous = YES; 14 [slider addTarget: self action: @ selector (sliderAction :) forControlEvents: UIControlEventValueChanged]; 15 16} 17 18 // slide the slider to change the view background color 19-(void) sliderAction :( UISlider *) slider20 {21 NSLog (@ "% f", slider. value); 22 self. view. backgroundColor = [UIColor colorWithRed: slider. value green: 1.0-slider. value blue: slider. value alpha: 1]; 23 24}
As follows:
3. Use the instance code for UIStepper and UIProgressView runners and progress bars
1 @ interface ViewController () 2 {3 UIProgressView * _ pro; 4} 5 @ end 6 7 @ implementation ViewController 8-(void) viewDidLoad {9 [super viewDidLoad]; 10 11 // The size information set is invalid. The size is fixed to 12 UIStepper * stepper = [[UIStepper alloc] initWithFrame: CGRectMake (10,100,300,200)]; 13 // you can set the maximum value of 14 stepper. maximumValue = 100; 15 // set the minimum value to 16 stepper. minimumValue = 0; 17 // set the current value to 18 stepper. value = 10; 19 // set the step value to 20 stepper. stepValue = 5; 21 // set the color 22 stepper. tintColor = [UIColor orangeColor]; 23 [self. view addSubview: stepper]; 24 [stepper addTarget: self action: @ selector (stepperAction :) forControlEvents: UIControlEventValueChanged]; 25 // progress bar, height invalid 26 UIProgressView * pro = [[UIProgressView alloc] initWithFrame: CGRectMake (10,200,300,100)]; 27 _ pro = pro; 28 29 // The value is 0.0-1.030 pro. progress = 0.5; 31 pro. progressTintColor = [UIColor redColor]; 32 [self. view addSubview: pro]; 33} 34 35 // change the progress bar value through the progress bar 36-(void) stepperAction :( UIStepper *) stepper37 {38 NSLog (@ "% f ", stepper. value); 39 _ pro. progress = stepper. value/stepper. maximumValue; 40}
As follows:
4. Use instance code for UISwitch and UIActivityIndicatorView switches and activity indicators
9-(void) viewDidLoad {10 [super viewDidLoad];
// Note that the page background color cannot be white; otherwise, the player cannot be seen because the player itself is white 12 self. view. backgroundColor = [UIColor blackColor]; 14 // The length and width are invalid. 15 UISwitch * s = [[UISwitch alloc] init]; 16 s. center = self. view. center; 17 // set the UISwitch switch status to 18 s. on = YES; 20 [self. view addSubview: s]; 21 [s addTarget: self action: @ selector (switchAction :) forControlEvents: UIControlEventValueChanged]; 22 _ activity = [[UIActivityIndicatorView alloc] failed: Failed]; 23 [self. view addSubview: _ activity]; 24 _ activity. center = CGPointMake (100,100); 25 [_ activity startAnimating];} 28 29-(void) switchAction :( UISwitch *) s30 {31 NSLog (@ "% d", s. on); 32 if (s. on) {33 // enable activity Indicator 34 [_ activity startAnimating]; 35} 36 else37 {38 // disable activity Indicator 39 [_ activity stopAnimating]; 40} 41}
As follows:
5. UITextView multi-line text box instance code
1-(void) viewDidLoad {2 [super viewDidLoad]; 3 4 // solve the problem of multi-line text box cursor not starting from the upper left corner 5 self. automaticallyAdjustsScrollViewInsets = NO; 6 // multi-line text box 7 UITextView * TV = [[UITextView alloc] initWithFrame: CGRectMake (10,100,300,100)]; 8 9 TV. backgroundColor = [UIColor grayColor]; 10 [self. view addSubview: TV]; 11 TV. delegate = self; 12} 13 14 // triggered when the content of the text box changes. The returned value indicates whether the content can be modified. 15-(BOOL) textView :( UITextView *) textView shouldChangeTextInRange :( nsange) range replacementText :( NSString *) text16 {17 // text change range 18 NSLog (@ "% @", NSStringFromRange (range )); 19 // text content 20 NSLog (@ "% @", text); 21 return YES; 22}