您的位置:首页 > 产品设计 > UI/UE

UIButton、UITextField、UISlider、UISwitch、UISegmentedControl

2016-05-01 11:32 615 查看

UIButton

//---------------------------创建-----------------------//
//button的样式
/******************************
UIButtonTypeCustom = 0,        自定义(常用)
UIButtonTypeDetailDisclosure,  感叹号
UIButtonTypeInfoLight,         感叹号
UIButtonTypeInfoDark,          感叹号
UIButtonTypeContactAdd,        +号
UIButtonTypeRoundedRect
******************************/
//创建button
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
//设置大小,坐标
button.frame = CGRectMake(100, 100, 100, 100);
//----------------------------属性----------------------//
//button的状态
/******************************
UIControlStateNormal       默认
UIControlStateHighlighted  高亮
UIControlStateSelected     选中
******************************/

//是否禁用
button.enabled = NO;
//设置选中状态

//设置标题
- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state;
//设置标题颜色
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state;
//设置某种状态下的图片
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;

//添加点击方法
- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;


UITextFiled

//创建UITextFiled
UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 60, 40)];
/*----------------------属性----------------*/
//设置边框
/*
UITextBorderStyleNone,        默认
UITextBorderStyleLine,        一条线
UITextBorderStyleBezel,       线有阴影
UITextBorderStyleRoundedRect  圆角矩形
*/
textFiled.borderStyle = UITextBorderStyleRoundedRect;
//输入文本类型
textFiled.keyboardType =  UIKeyboardTypeDefault ;
//return类型
textFiled.returnKeyType = UIReturnKeyEmergencyCall;
//清除模式
/***************************************
UITextFieldViewModeNever,           从不
UITextFieldViewModeWhileEditing,    编辑时
UITextFieldViewModeUnlessEditing,   不编辑时
UITextFieldViewModeAlways           总是
***************************************/
textFiled.clearButtonMode =  UITextFieldViewModeUnlessEditing;
//提示(输入时消失)
textFiled.placeholder = @"请输入密码";
//密码模式(输入隐藏)
textFiled.secureTextEntry = YES;
//首字母大写(default is UITextAutocapitalizationTypeSentences)
/***************************************
UITextAutocapitalizationTypeNone,           全都不大写
UITextAutocapitalizationTypeWords,          单词首字母大写
UITextAutocapitalizationTypeSentences,      句子首字母大写
UITextAutocapitalizationTypeAllCharacters,  全都大写
***************************************/
textFiled.autocapitalizationType = UITextAutocapitalizationTypeWords;
//单词联想
/***************************************
UITextAutocorrectionTypeDefault,  默认
UITextAutocorrectionTypeNo,       关
UITextAutocorrectionTypeYes,      开
***************************************/
textFiled.autocorrectionType = UITextAutocorrectionTypeYes;


UIslider

//创建UISlider
UISlider * slider = [[UISlider alloc] initWithFrame:CGRectMake(100, 100, 200, 30)];
//-------------------属性-----------------------
//滑块的最大值
slider.maximumValue = 100;
//最小值
slider.minimumValue = 0;
//当前值
slider.value = 20;
//滑动条颜色
//右边滑动过的颜色
slider.maximumTrackTintColor = [UIColor yellowColor];
//左面滑动过的颜色
slider.minimumTrackTintColor = [UIColor redColor];
//滑动样式
//中心样式
[slider setThumbImage:[UIImage imageNamed:@"playing_btn_in_myfavor"] forState:UIControlStateNormal];
//滑过的样式
- (void)setMinimumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
//未滑过的样式
- (void)setMaximumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
//为滑动块添加事件
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];


UISwitch

//on时switch的颜色
@property(nullable, nonatomic, strong) UIColor *onTintColor
//off时switch的颜色
@property(null_resettable, nonatomic, strong) UIColor *tintColor
//拇指的颜色
@property(nullable, nonatomic, strong) UIColor *thumbTintColor

//on时的图片
@property(nullable, nonatomic, strong) UIImage *onImage
//off时的图片
@property(nullable, nonatomic, strong) UIImage *offImage
//默认开关
@property(nonatomic,getter=isOn) BOOL on;
//添加事件
[switch addTarget:self action:@selector(switchOn) forControlEvents:UIControlEventValueChanged];


UISegmentedControl

//创建索引控制器(初始化时可以添加多个条目)
UISegmentedControl * segmentControl = [[UISegmentedControl alloc] initWithItems:@[@"start",@"stop",@"HMT"]];
//插入带标题的索引
- (void)insertSegmentWithTitle:(nullable NSString *)title atIndex:(NSUInteger)segment animated:(BOOL)animated;
//插入带图片的索引
- (void)insertSegmentWithImage:(nullable UIImage *)image  atIndex:(NSUInteger)segment animated:(BOOL)animated;
//为某个索引设置标题
- (void)setTitle:(nullable NSString *)title forSegmentAtIndex:(NSUInteger)segment;
//为某个索引设置图片
- (void)setImage:(nullable UIImage *)image forSegmentAtIndex:(NSUInteger)segment;
//移除某个下标下的索引
- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated;
//添加事件
[segmentControl addTarget:self action:@selector(selector) forControlEvents:UIControlEventValueChanged];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: