UIButton和UISlider

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.
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值