IOS development-UI (1) common controls, ios development-ui controls
From here on is the UI
Knowledge point:
1. Common basic IOS controls
2. UITouch
======================================
Common basic controls
1. UISegmentedControl: segment controller
1) Creation Method
-(Id) initWithItems :( NSArray *) items;
The items array can contain NSString or UIImage objects.
UISegmentedControl * seg = [[UISegmentedControl alloc] initWithItems: @ [@ "Guangzhou", @ "Shenzhen", @ "Zhuhai"];
2) common attributes
Set the title/image (note that the subscript ranges from 0 ~ Segments-1)
- (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment[seg setImage:[UIImage imageNamed:@"refresh_30"] forSegmentAtIndex:2];
Insert title/Image
- (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated- (void)insertSegmentWithImage:(UIImage *)image atIndex:(NSUInteger)segment animated:(BOOL)animated
// Insert
[Seg insertSegmentWithTitle: @ "Zhanjiang" atIndex: 3 animated: YES];
Removed content-(void) removeSegmentAtIndex :( NSUInteger) segment animated :( BOOL) animated-(void) removeAllSegments // remove a segment [seg removeSegmentAtIndex: 0 animated: YES]; // remove all segments [seg removeAllSegments];
Event Processing
-(Void) addTarget :( id) target
Action :( SEL) action
ForControlEvents :( UIControlEvents) controlEvents
3) event handling
UIControlEventValueChanged
// Add an event
// Note the event type: UIControlEventValueChanged
[Seg addTarget: self action: @ selector (segAction :) forControlEvents: UIControlEventValueChanged];
2. UISlider: Slider
1) Creation Method
2) common attributes
Current value
Property (nonatomic) float value
// Instantiate a UISlider
UISlider * slider = [[UISlider alloc] initWithFrame: CGRectMake (10, 80,200,100)];
// Set the default slider position (the default value is 0-1)
Slider. value = 0.5;
Minimum value
@ Property (nonatomic) float minimumValue
Maximum value
@ Property (nonatomic) float maximumValue
// Modify the maximum and minimum values
Slider. minimumValue = 10;
Slider. maximumValue = 100;
3) custom UI
@ Property (nonatomic, retain) UIColor * minimumTrackTintColor @ property (nonatomic, retain) UIColor * maximumTrackTintColor @ property (nonatomic, retain) UIColor * thumbTintColor // Add event [sliaddder target: self action: @ selector (sliderAction :) forControlEvents: UIControlEventValueChanged]; // you can specify the slider color. minimumTrackTintColor = [UIColor redColor]; slider. maximumTrackTintColor = [UIColor yellowColor]; slider. thumbTintColor = [UIColor purpleColor];
3. UISwitch: Switch Control
1) Creation Method
// Instantiate a UISwitch
UISwitch * swi = [UISwitch alloc] initWithFrame: CGRectMake (30, 80, 10, 10)];
2) common attributes
@ Property (nonatomic, retain) UIColor * onTintColor
@ Property (nonatomic, retain) UIColor * thumbTintColor
@ Property (nonatomic, getter = isOn) BOOL on
// Set the Key Color
Swi. thumbTintColor = [UIColor orangeColor];
// Open color
Swi. onTintColor = [UIColor purpleColor];
// Set the Switch Status
Swi. on = NO;
3) event handling
[Swi addTarget: self action: @ selector (swiAction :) forControlEvents: UIControlEventValueChanged];
4. UIActivityIndicatorView
1) Creation Method
-(Id) initWithActivityIndicatorStyle :( UIActivityIndicatorViewStyle) style
UIActivityIndicatorViewStyleWhiteLarge large white
UIActivityIndicatorViewStyleWhite normal size white
UIActivityIndicatorViewStyleGray normal gray
// Load the view
UIActivityIndicatorView * act = [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake (30,100,200,200)];
Act. activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
2) common attributes
Start to rotate
-(Void) startAnimating;
Stop Rotation
-(Void) stopAnimating;
Rotating or not
-(BOOL) isAnimating;
Color
@ Property (readwrite, nonatomic, retain) UIColor * color
// Set the color
Act. color = [UIColor orangeColor];
// Enable the animation
[Act startAnimating];
// Stop the animation
[Act stopAnimating];
// Set the animation to be stopped.
Act. hidesWhenStopped = NO;
5. UIProgressView: progress bar
1) Creation Method
-(Id) initWithProgressViewStyle :( UIProgressViewStyle) style
UIProgressView * pro = [[UIProgressView alloc] initWithFrame: CGRectMake (30,100,200, 30)];
2) common attributes
@ Property (nonatomic) float progress current progress
@ Property (nonatomic, retain) UIColor * trackTintColor
@ Property (nonatomic, retain) UIColor * progressTintColor
// The default value range is 0-1.
// Set the progress
Pro. progress = 0.5;
// Completion progress color
Pro. progressTintColor = [UIColor redColor];
// The Color of the unfinished progress
Pro. trackTintColor = [UIColor greenColor];
Exercise: Simulate the progress reading status
6. UIActionSheet
Proxy Method
// Instantiate a UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle: @ "tip" delegate: self cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "dinner" tip: @ "shopping", @ "playing games", @ "sleeping", nil]; // display UIActionSheet [sheet showInView: self. view];-(void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex // click the callback proxy method-(void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex {NSLog (@ "buttonIndex = % ld", buttonIndex); switch (buttonIndex) {case 0: {NSLog (@ "");} break; default: break ;}}
7. UIAlertView
-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {
// Instantiate a UIAlertView
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "tip" message: @ "insufficient balance" delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: @ "rob Bank ", @ "moving bricks", @ "finding a rich woman", nil];
// Display
[Alert show];
}
# Pragma mark-UIAlertViewDelegate
-(Void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {
NSLog (@ "buttonIndex = % ld", buttonIndex );
}
======================================
UITouch
1. How to capture touch events
Touch start-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event; move-(void) touchesMoved :( NSSet *) touches withEvent :( UIEvent *) event; touch finish-(void) touchesEnded :( NSSet *) touches withEvent :( UIEvent *) event; touch canceled (Program interrupted during touch)-(void) touchesCancelled :( NSSet *) touches withEvent :( UIEvent *) event;-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {// obtain the starting coordinate // obtain the touch point object UITouch * touch = [touches anyObject]; // convert it to the coordinate point CGPoint = [touch locationInView: self. view];}
2. How to obtain coordinate information
1) obtain the touch point
UITouch * touch = [touches anyObject]
// Obtain the starting Coordinate
// Obtain the touch Point Object
UITouch * touch = [touches anyObject];
2) convert to coordinate point
[Touch locationInView: self. view]
CGPoint point = [touch locationInView: self. view];