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)state
eg:[button setBackgroundImage:[UIImage imageNamed:@"xiaogou.jpg"] forState:UIControlStateNormal];

//给按钮加入目标及行为
- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
eg:[button addTarget:self action:@selector(onButton) forControlEvents:UIControlEventTouchUpInside];

UISlider

主要功能:滑块属性。用于控制某一范围内值得设置。如声音大小控制,音乐播放进度。

经常使用属性和方法:

@property(nonatomic) float value;//在某一时刻或者某一位置UISlider所表示的值,默认是0.0
NSLog(@"%f",self.slider.value);

@property(nonatomic) float minimumValue;//UISlider坐标是范围的最小值。

 

默认是0.0 NSLog(@"%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.
}

}