【其他控件】
1、UISlider 滑块控件
介绍:继承自UIControl,为事件驱动型控件,高度固定23,frame设置高度无效果
方法:
1)@property(nonatomic)CGRect frame;
设置滑块的尺寸
2)@property(nonatomic)float maximumValue
设置滑块的最大值,默认值(0.0 1.0)
3)@property(nonatomic)float minimumValue
设置滑块的最小值
4)@property(nonatomic)float value
设置滑块最初显示的数值,滑动滑块,伴随的value值的改变
5)@property(nonatomic,getter=isContinuous)BOOL continuous
控制滑块的值是否时时变化,默认为YES
6)- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
给滑块添加方法
7)UIControlEventValueChanged 当控件的值发生变化时所对应的事件
2、UISegmentedControl 分段选取器
介绍:事件驱动型控件,分段选取器会根据文字内容给一个合适的size
1)- (id)initWithItems:(NSArray *)items;
初始化传递进去的NSArray里面放置字符串或图片
2)@property(nonatomic)CGRect frame;
不要忘记设置frame
3)@property(nonatomic)NSInteger selectedSegmentIndex;
设置哪个分段处于选中状态,不设置此属性,任何分段都处于非选中状态
4)- (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated
向分段选取器指定的位置插入标题
5)- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
给分段选取器添加方法
6)- (NSString *)titleForSegmentAtIndex:(NSUInteger)segment
根据分段的下标,拿到分段的标题
3、UIStepper 步进器
介绍:固定的size (94*27), 事件驱动型控件
1)@property(nonatomic)double maximumValue
设置最大值
2)@property(nonatomic)double minimumValue
设置最小值
3)@property(nonatomic)double stepValue
设置步长 (默认值为1 必须>0)(+一次增加的值/-一次减少的值)
4)@property(nonatomic,getter=isContinuous)BOOL continuous
设置长按是否连续响应事件
5)- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
给步进器添加方法
4、UIProgressView 进度条
介绍:进度条,普通视图控件,高度固定9
1)@property(nonatomic)float progress
进度条的进度属性(默认为0,0.0-1.0),值大于1,进度条一直处于满格状态
5、UISwitch 开关
介绍:开关控件,事件驱动型控件,固定size(79*27),frame更改size无效
1)@property(nonatomic,getter=isOn)BOOL on
控制开关的开闭(YES 开)
2)- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
添加事件
6、UIActivityIndicatorView加载等待提示控件
介绍:加载等待提示控件,控件的size固定
1)- (id)initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyle)style
初始化的时候,设定风格样式
2)@property(nonatomic)CGPoint center
一般设置中心点为view的中心点
3)- (void)startAnimating;
让提示控件转动
4)- (void)stopAnimating;
让提示控件停止转动
7、UIAlertView
介绍:(视图控件-警告框)
1)- (id)initWithTitle:(NSString *)title
message:(NSString *)message
delegate:(id)delegate
cancelButtonTitle: (NSString*)cancelButtonTitle
otherButtonTitles: (NSString*)otherButtonTitles, ...
初始化
举例:
UIAlertView *alert = [[UIAlertViewalloc]
initWithTitle:@“xxx”
message:@"xxx"
delegate:self
cancelButtonTitle:@"0"
otherButtonTitles:@"1",@"2",nil];
2)- (void)show;
显示警告框,同时将alert托管给应用程序
3)- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
当点击警告框上的按钮时,触发此方法,buttonIndex 按钮在警告框上的位置
8、UIActionSheet
介绍:动作表单
1)- (instancetype)initWithTitle:(NSString*)title
delegate:(id)delegate
cancelButtonTitle:(NSString*)cancelButtonTitle
destructiveButtonTitle: (NSString*)destructiveButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, ...
初始化
举例:
UIActionSheet *atSheet=[[UIActionSheetalloc]
initWithTitle:@“xxxx”
delegate:self
cancelButtonTitle:@"x"
destructiveButtonTitle:nil
otherButtonTitles:@"0",@"1",@"...",@"x-1",nil];
2)- (void)showInView:(UIView *)view;;
在view上显示动作表单
3)- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
当点击动作表单上的按钮时,触发此方法,buttonIndex 按钮在动作表单上的位置
上面两种方法放在一起用 如下
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{//当被点击的时候,会调用这个方法
//举例:当有输入框的时候,点击空白,隐藏键盘。这个功能可以在这个方法里面写
#if 0 下面三个红的是c语言知识
UIAlertView *uav=[[UIAlertView alloc]initWithTitle:@"⚠" message:@"你妈妈叫你回去吃饭" delegate:self cancelButtonTitle:@"残忍拒绝" otherButtonTitles:@"去app好评",@"待会再说",nil];
[uav show];
#else
UIActionSheet *US=[[UIActionSheetalloc]initWithTitle:@"分享"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"QQ",@"微信",@"人人",nil];
[US showInView:self.view];
#endif
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{//还有好多方法,这个方法是最常用的
NSLog(@"%ld",buttonIndex);
if (buttonIndex==1) {
NSLog(@"小子不错");
}else if (buttonIndex==2){
NSLog(@"我等着");
}else if (buttonIndex==0){
NSLog(@"