码迷,mamicode.com
首页 > 其他好文 > 详细

UIButton和UISlider

时间:2015-07-05 18:38:28      阅读:141      评论:0      收藏:0      [点我收藏+]

标签: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.
}

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

UIButton和UISlider

标签:uibutton   控件   uislider   

原文地址:http://blog.csdn.net/wow09_1225/article/details/46763863

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!