关闭

iOS控件之UISlider

250人阅读 评论(0) 收藏 举报
分类:
滑动控件UISlider视图

一,作用:控制系统声音,或者表示播放进度等等

二,常用属性
// 设置获取slider的value值
@property(nonatomic) float value;


// 设置slider的最小值
@property(nonatomic) float minimumValue;


// 设置slider的最大值
@property(nonatomic) float maximumValue;


// 设置图片
@property(nonatomic,retain) UIImage *minimumValueImage;


// 设置图片
@property(nonatomic,retain) UIImage *maximumValueImage;


// 设置slider的value值,是否存在动画

- (void)setValue:(float)value animated:(BOOL)animated


三,UISliderDemo

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(60, 100, 200, 20)];
    slider.tag = 101;
    slider.maximumValue = 10;
    slider.minimumValue = 0;
//    [slider addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
//    [slider addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [slider addTarget:self action:@selector(test1) forControlEvents:UIControlEventTouchDragInside];
    [slider addTarget:self action:@selector(test2) forControlEvents:UIControlEventTouchDragOutside];
//    slider.value = 5; // 0 ~ 1
    [self.window addSubview:slider];
    [slider release];
    
//    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:slider repeats:NO];
    
    return YES;
}

- (void)test:(NSTimer *)timer
{
    UISlider *slider = [timer userInfo];
    [slider setValue:5 animated:NO];
}

- (void)change:(UISlider *)slider
{
    NSLog(@"slider value : %.2f", slider.value);
}

- (void)touchUpInside:(UISlider *)slider
{
    NSLog(@"touchUpInside : %.2f", slider.value);
}

- (void)test1
{
    NSLog(@"test1");
}

- (void)test2
{
    NSLog(@"test2");    
}



1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:57116次
    • 积分:1534
    • 等级:
    • 排名:千里之外
    • 原创:91篇
    • 转载:31篇
    • 译文:1篇
    • 评论:3条
    博客专栏
    最新评论