從這裡開端是UI篇
知識點:
1.常用IOS根本控件
2.UITouch
=======================
常用根本控件
1.UISegmentedControl:分段控制器
1)創立方式
- (id)initWithItems:(NSArray *)items;
items數組中可以有NSString或許是UIImage對象
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"廣州",@"深圳",@"珠海"]];
2)常用屬性
設置標題/圖片(留意下標范圍從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];
拔出標題/圖片
- (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated - (void)insertSegmentWithImage:(UIImage *)image atIndex:(NSUInteger)segment animated:(BOOL)animated
//拔出
[seg insertSegmentWithTitle:@"湛江" atIndex:3 animated:YES];
移除內容 - (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated - (void)removeAllSegments //移除某一個分段 [seg removeSegmentAtIndex:0 animated:YES]; //移除一切分段 [seg removeAllSegments];
事情處置
- (void)addTarget:(id)target
action:(SEL)action
forControlEvents:(UIControlEvents)controlEvents
3)事情處置
UIControlEventValueChanged
//添加事情
//留意事情類型運用:UIControlEventValueChanged
[seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
2.UISlider:滑塊
1)創立方式
2)常用屬性
以後value
property(nonatomic) float value
//實例化一個UISlider
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 80, 200, 100)];
//設置默許滑塊的地位(默許是0 - 1范圍)
slider.value = 0.5;
最小value
@property(nonatomic) float minimumValue
最大value
@property(nonatomic) float maximumValue
//修正最大最小值
slider.minimumValue = 10;
slider.maximumValue = 100;
3)定制UI
@property(nonatomic,retain) UIColor *minimumTrackTintColor @property(nonatomic,retain) UIColor *maximumTrackTintColor @property(nonatomic,retain) UIColor *thumbTintColor //添加事情 [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged]; //設置左右顏色 slider.minimumTrackTintColor = [UIColor redColor]; slider.maximumTrackTintColor = [UIColor yellowColor]; slider.thumbTintColor = [UIColor purpleColor];
3.UISwitch:開關控件
1)創立方式
// 實例化一個UISwitch
UISwitch *swi = [[UISwitch alloc] initWithFrame:CGRectMake(30, 80, 10, 10)];
2)常用屬性
@property(nonatomic, retain) UIColor *onTintColor
@property(nonatomic, retain) UIColor *thumbTintColor
@property(nonatomic,getter=isOn) BOOL on
//設置按鍵顏色
swi.thumbTintColor = [UIColor orangeColor];
//翻開的顏色
swi.onTintColor = [UIColor purpleColor];
//設置開關形態
swi.on = NO;
3)事情處置
[swi addTarget:self action:@selector(swiAction:) forControlEvents:UIControlEventValueChanged];
4.UIActivityIndicatorView
1)創立方式
- (id)initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style
UIActivityIndicatorViewStyleWhiteLarge 大白色
UIActivityIndicatorViewStyleWhite 普通大小白
UIActivityIndicatorViewStyleGray 普通大小灰
// 加載視圖
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(30, 100, 200, 200)];
act.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
2)常用屬性
開端轉動
- (void)startAnimating;
中止轉動
- (void)stopAnimating;
能否正在轉動
- (BOOL)isAnimating;
顏色
@property (readwrite, nonatomic, retain) UIColor *color
//設置顏色
act.color = [UIColor orangeColor];
//開啟動畫
[act startAnimating];
//中止動畫
[act stopAnimating];
//設置中止動畫仍然顯示
act.hidesWhenStopped = NO;
5.UIProgressView:進度條
1)創立方式
- (id)initWithProgressViewStyle:(UIProgressViewStyle)style
UIProgressView *pro = [[UIProgressView alloc] initWithFrame:CGRectMake(30, 100, 200, 30)];
2)常用屬性
@property(nonatomic) float progress 以後進度
@property(nonatomic, retain) UIColor* trackTintColor
@property(nonatomic, retain) UIColor* progressTintColor
//默許的范圍為0 - 1
//設置進度
pro.progress = 0.5;
//完成進度的顏色
pro.progressTintColor = [UIColor redColor];
//未完成進度的顏色
pro.trackTintColor = [UIColor greenColor];
練習:模擬進度讀取形態
6.UIActionSheet
代理辦法
//實例化一個UIActionSheet UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"溫馨提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"吃飯" otherButtonTitles:@"逛街",@"打游戲", @"睡覺",nil]; //顯示UIActionSheet [sheet shoWinView:self.view]; - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex //點擊回調代理辦法 -(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{
//實例化一個UIAlertView
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"余額缺乏" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:@"搶銀行",@"搬磚",@"找個富婆", nil];
//展現
[alert show];
}
#pragma mark- UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"buttonIndex = %ld",buttonIndex);
}
=======================
UITouch
1.如何捕獲觸摸事情
觸摸開端 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 挪動 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 觸摸完畢 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 觸摸被取消(觸摸時分順序被中綴) - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event; -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ //取得起始坐標 //獲得觸摸點對象 UITouch *touch = [touches anyObject]; //轉換成坐標點 CGPoint point = [touch locationInView:self.view]; }
2.如何獲取坐標信息
1)獲取到觸摸點
UITouch *touch=[touches anyObject]
//取得起始坐標
//獲得觸摸點對象
UITouch *touch = [touches anyObject];
2)轉換為坐標點
[touch locationInView:self.view]
CGPoint point = [touch locationInView:self.view];
【iOS開發-UI (一)常用控件】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!