UIButton和UISlider
来源:互联网 发布:解放台湾 知乎 编辑:程序博客网 时间:2024/04/30 01:03
UIButton
主要功能:按钮控件,主要用于与用户操作进行交互
常用属性及方法
系统内建的按钮类型
UIButtonTypeCustom
UIButtonTypeSystem
UIButtonTypeDetaiDislosure
UIButtonTypeInfoLight
UIButtonTypeContactAdd
UIButtonTypeRoundedRect
系统中关于控件的状态类型
UIControlStateNormol
UIControlStateHighlighted
UIControlStateDisabled
UIControlStateSelected
UIControlStateApplication
UIControlStateReserved
几种常见设置UIButton方法
//根据UIButtonType创建不同天系统内建风格的按钮+ (id)buttonWithType:(UIButtonType)buttonType;eg:UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];//根据按钮状态设置按钮的标题- (void)setTitle:(NSString *)title forState:(UIControlState)state;[button setTitle:@"BTN" forState:UIControlStateNormal];//根据按钮状态设置按钮上的文字颜色- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;eg:[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];//根据按钮状态设置按钮的图片- (void)setImage:(UIImage *)image forState:(UIControl)eg:[button setImage:[UIImage imageNamed:@"xiaogou.jpg"] forState:UIControlStateNormal];//根据按钮状态设置背景图片- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)stateeg:[button setBackgroundImage:[UIImage imageNamed:@"xiaogou.jpg"] forState:UIControlStateNormal];//给按钮添加目标及行为- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEventseg:[button addTarget:self action:@selector(onButton) forControlEvents:UIControlEventTouchUpInside];
UISlider
主要功能:滑块属性,用于控制某一范围内值得设置,如声音大小控制,音乐播放进度。
常用属性和方法:
@property(nonatomic) float value;//在某一时刻或者某一位置UISlider所表示的值,默认是0.0NSLog(@"%f",self.slider.value);@property(nonatomic) float minimumValue;//UISlider坐标是范围的最小值。默认是0.0NSLog(@"%f",self.slider.minimumValue);@property(nonatomic) float maximumValue;//UISlider所表示范围的最大值,默认是1.0//最小值时的图片,在UISlider的左边,默认是nil@property(nonatomic, retain) UIImage *minimumValueImage;self.slider.minimumValueImage = [UIImage imageNamed:@"xiaogou.jpg"];//最大值是的图片,在UISlider的右边,默认是nil@property(nonatomic, retain) UIImage *maximumValueImage;self.slider.maximumValueImage = [UIImage imageNamed:@"xiaogou.jpg"];//设置UISlider对象的值- (void) setValue:(float)value animated:(BOOL)animated;- //让滑块以一定的速度自动滑动
代码演示:
让滑块自动的以一定的速度滑动
#import "ViewController.h"@interface ViewController ()@property (weak,nonatomic) UISlider *slider;//滑块控件是拖拽过来的@end@implementation ViewController- (void)viewDidLoad { self.slider.minimumValue = 0.0; self.slider.maximumValue = 1000.0; self.slider.minimumTrackTintColor = [UIColor redColor]; self.slider.maximumTrackTintColor = [UIColor greenColor]; self.slider.thumbTintColor = [UIColor purpleColor]; UIButton *btnType = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnType.backgroundColor = [UIColor blueColor]; btnType.frame = CGRectMake(100,300,100,60); [self.view addSubview:btnType];- (void)onTimer:(NSTimer *)timer{ static float value = 10; value +=5; [self.slider setValue:value animated:YES]; NSLog(@"%f",self.slider.value);}- (void)onButton{ [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimer:) userInfo:nil repeats:NO];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}}
0 0
- UIButton和UISlider
- UIButton、UITextField、UISlider、UISwitch、UISegmentedControl
- UIButton+UIImageView+UISlider+UISwitch操作总结
- 手势和UI控件之间冲突的解决方法(比如UITapGesture和UIButton冲突,UIPanGesture和UISlider冲突)
- 手势和UI控件之间冲突的解决方法(比如UITapGesture和UIButton冲突,UIPanGesture和UISlider冲突)
- 手势和UI控件之间冲突的解决方法(比如UITapGesture和UIButton冲突,UIPanGesture和UISlider冲突)
- 手势和UI控件之间冲突的解决方法(比如UITapGesture和UIButton冲突,UIPanGesture和UISlider冲突)
- 手势和UI控件之间冲突的解决方法(比如UITapGesture和UIButton冲突,UIPanGesture和UISlider冲突)
- UIProgressView和UISlider
- UISegmentControl 和UIslider
- UISlider 和 UISegement
- 27.UIStepper和UISlider
- UISlider和UIImageView
- UISlider和UIProgressView
- IOS代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl
- Swift UI学习之基础:UIButton,UILabel and UISlider
- IOS代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl
- IOS代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl
- js lodash 'date' 'nunber' 'math' methods
- LeetCode #002 Add Two Numbers
- 黑马程序员——Java集合框架—整理笔记
- Python_Monkeyrunner
- 《java课程设计》之猜猜看游戏(三)
- UIButton和UISlider
- Linux系统用到命令积累
- wget的下载与安装使用
- 每天学习一点新东西--vim篇(一)
- 【字符串数据结构后缀系列Part1】后缀数组学习笔记
- 课程设计:ATM机模拟系统
- 单独编译Android的image文件
- UITextField / UIButton / 回收键盘delegate
- 黑马程序员——NSLog的使用方法及NSLog与prinft的差异