This article mainly introduces the rest of the more common UI controls, mainly including UIActivityIndicatorView, UIStepper, UISegmentControl, UIProgressView.

Related articles:

TextField basic usage several small controls commonly used to build UI (1)

UIActivityIndicatorView

UIActivityIndicatorView is actually not a very commonly used UI control, now most apps are through third-party libraries or their own custom controls to achieve functions, but because the secondary control is still a relatively basic control, so in this article or to carry out a simple introduction.

UIActivityIndicatorView inherits from UIView.

UIActivityIndicatorView* aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; / / initialize create UIActivityIndicatorViewStyleWhiteLarge UIActivityIndicatorViewStyleWhite / / / / out this small white UIActivityIndicatorViewStyleGray / / gray aiv. Transform = CGAffineTransformMakeScale (3, 5); // Change the size using the deform property aiv.bounds = CGRectMake(0, 0, 320, 480); // The size of the bounds property cannot be changed, so the center should be changed - (void)startAnimating; // Start animation - (void)stopAnimating; // Stop animation - (BOOL)isAnimating; // Determine the statusCopy the code

UIStepper

UIStepper * stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 100, 10, 10)]; Stepper. MaximumValue = 100.0; Stepper. MinimumValue = 0.0; Stepper. Value = 60.0; // Set the change interval, default is 1 stepper. StepValue = 0.5; Continuous = YES; stepper. Continuous = YES; stepper. Continuous = YES; // Set whether to automatically grow stepper. Autorepeat = YES; Wraps = NO; // Wraps = NO; // Set stepper. TintColor = [UIColor redColor]; / / add event [stepper addTarget: self action: @ the selector (valueChanged:) forControlEvents: UIControlEventValueChanged]; // Set background image, picture big, Stepper get bigger [stepper setBackgroundImage: [UIImage imageNamed: @ "Image1"] forState: UIControlStateNormal]; [stepper setBackgroundImage:[UIImage imageNamed:@"Image2"] forState:UIControlStateHighlighted]; / / set the line images (understand) [stepper setDividerImage: [UIImage imageNamed: @ "Image3"] forLeftSegmentState: UIControlStateHighlighted rightSegmentState:UIControlStateNormal]; // Depending on the state of the two keys, you can set multiple pictures // get a picture of a state // Because each state can have different pictures, this method can get a picture of the state. UIImage * image = [stepper dividerImageForLeftSegmentState:UIControlStateHighlighted rightSegmentState:UIControlStateNormal]; [stepper setDividerImage:image forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateHighlighted]; image = [[UIImage imageNamed:@"Image4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; / / set plus (minus) picture [stepper setIncrementImage: image forState: UIControlStateNormal];Copy the code

UISegmentControl

SegementControl is a very common UI control, used as different partitions of the same page, etc.

NSArray * items = @[@" big ", image, @" big "]; // create SC UISegmentedControl * SC = [[UISegmentedControl alloc] initWithItems:items]; // Add coordinates sc.frame = CGRectMake(50, 100, 200, 50); // set tintColor sc.tintColor = [UIColor redColor]; // Set the currently selected segment sc.selectedSegmentIndex = 2; // This method can also determine the segment that is currently selected. // The segment that is currently selected cannot be selected. // Set a segment width [sc setWidth:0 forSegmentAtIndex:1]; / / if the value is YES, the segment 0 width, the adaptive / / sc apportionsSegmentWidthsByContent = YES; // Set a segment to invalid [sc setEnabled:NO forSegmentAtIndex:2]; / / determine whether a particular segment effective BOOL ret = [sc isEnabledForSegmentAtIndex: 2]; NSLog(@"%d", ret); // Set a segment title [sc setTitle:@" Silly "forSegmentAtIndex:0]; //- (NSString *)titleForSegmentAtIndex:(NSUInteger)segment; // Set a segment image [sc setImage:image forSegmentAtIndex:2]; // - (UIImage *)imageForSegmentAtIndex:(NSUInteger)segment; / / / / return photographs add event [sc addTarget: self action: @ the selector (valueChanged:) forControlEvents: UIControlEventValueChanged]; / / add a background image [sc setBackgroundImage: [UIImage imageNamed: @ "10 _0. JPG] forState: UIControlStateNormal barMetrics:UIBarMetricsDefault]; // Horizontal screen vertical screen, can set two backgroundsCopy the code

UIProgressView

UIProgressView is not very common at the moment and is mostly used for apps that have audio or video playback capabilities. Similarly, UIProgressView inherits from UIView.

UIProgressView * pv = [[UIProgressView alloc] initWithFrame:CGRectMake(10, 400, 300, 10)]; pv.tag = 1; Pv.progress = 0; pv.progress = 0; // set tintColor pv. TintColor = [UIColor redColor]; pv.trackTintColor = [UIColor yellowColor]; / / if you want to widen the progress bar pv. Transform = CGAffineTransformMakeScale (1, 10); Pv. transform = CGAffineTransformRotate(pv.transform, -m_pi_2); / / add images to set stretch of vertical lines UIImage * image1 = [[UIImage imageNamed: @ "image1"] stretchableImageWithLeftCapWidth: 5 topCapHeight: 0]; UIImage * image2 = [[UIImage imageNamed:@"image2"] stretchableImageWithLeftCapWidth:50 topCapHeight:0]; pv.trackImage = image2; pv.progressImage = image1;Copy the code