//根据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];
@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.
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wow09_1225/article/details/46763863