10、UISlider-OC+UI

UISlider 介绍

UISlider 常用属性

10、UISlider-OC+UI_第1张图片

UISlider常用方法

10、UISlider-OC+UI_第2张图片


#import "ccyAppDelegate.h"

@implementation ccyAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    
    UISlider * slider = [[UISlider alloc] init];
    //slider.frame = CGRectMake(10, 100, 300, 100);
    //这里最后一个设置为0,此时无法控制滑动轴
    slider.frame = CGRectMake(10, 100, 300, 100);
    slider.backgroundColor = [UIColor redColor];
    //
    slider.value = 0.5;
    //事件触发
    [slider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];
    
    //最小值和最大值要同时设置
    slider.minimumValue = 100;
    slider.maximumValue = 101;
    //最小值和最大值 一侧图片
    slider.minimumValueImage = [UIImage imageNamed:@""];
    slider.maximumValueImage = [UIImage imageNamed:@""];
    //最小值和最大值  轨道图片
    slider.minimumTrackTintColor = [UIColor redColor];
    slider.maximumTrackTintColor = [UIColor blackColor];
    //滑块颜色设置
    slider.thumbTintColor = [UIColor orangeColor];
    //设置动画滑块初始值[能看到滑块会移动]
    [slider setValue:100.5 animated:YES];
    //设置滑块图片“UIControlStateNormal”[之前设置滑块颜色就不能显示]
    [slider setThumbImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    //设置轨道图片
    [slider setMinimumTrackImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    
    [self.window addSubview:slider];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)sliderChange:(id)arg
{
    UISlider * slider = (UISlider *)arg;
    NSLog(@"v = %f", slider.value);
}



你可能感兴趣的:(10、UISlider-OC+UI)