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];
相关文章推荐
- HDU 1242 Rescue(图)
- 笔记3:FileWebRequest 与 FileWebResponse
- POJ 2031 Building a Space Station(最小生成树)
- HDU_4069_SquigglySudoku(DancingLinksX精确覆盖+BFS)
- Leetcode:63. Unique Paths II
- android UI(1)-PopupWindow
- Leetcode:62. Unique Paths
- 安卓handler
- How to solve Dell laptops fan issues in Ubuntu
- String、StringBuffer和StringBuider
- Druid数据库连接池的使用
- [Nordic][nRF51822][Build Break] identifier "GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS" is undefined
- 2016 UESTC Training for Data Structures 题解
- UIIMage与CGImage的关系
- Tab Bar Item
- LeetCode 334. Increasing Triplet Subsequence
- 对自定义UITableViewCell的理解
- nRF51822 自定义UUID,ble_advdata_set的时候 NRF_ERROR_DATA_SIZE 错误的解决
- 2016 UESTC Training for Data Structures R - Japan 树状数组求逆序数
- 2016 UESTC Training for Data Structures Q - 昊昊爱运动 II 线段树+延迟操作+bitset