UI17UISlider+UISwitch

//

//  RootViewController.m

//  UI17UISlider+UISwitch

//

//  Created by focus on 2017/1/22.

//  Copyright © 2017年 focus. All rights reserved.

//

 

#import "RootViewController.h"

 

@interface RootViewController ()

{

    UITextField *tf;

}

@end

 

@implementation RootViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    //开关 UISwitch

    UISwitch * sw= [[UISwitch alloc] initWithFrame:CGRectMake(10, 50, 0, 0)];

    [self.view addSubview:sw];

    //设置开关打开的颜色

    //sw.onTintColor = [UIColor blueColor];

    //sw.thumbTintColor = [UIColor orangeColor];

    //sw.tintColor = [UIColor greenColor];

    //默认打开

    sw.on = YES;

    //给开关添加事件

    [sw addTarget:self action:@selector(swChange:) forControlEvents:UIControlEventValueChanged];

    

    //添加TextField

    tf = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 40)];

    tf.backgroundColor = [UIColor redColor];

    [self.view addSubview:tf];

    

    //滑动条UISlider

    UISlider *slid = [[UISlider alloc] initWithFrame:CGRectMake(10, 150, 200, 30)];

    [self.view addSubview:slid];

    slid.thumbTintColor = [UIColor grayColor];

    slid.maximumTrackTintColor = [UIColor yellowColor];

    slid.minimumTrackTintColor = [UIColor redColor];

    //设置最大最小值

    slid.maximumValue = 100.0;

    slid.minimumValue = 0.0;

    //添加事件

    [slid addTarget:self action:@selector(sliderEvent:) forControlEvents:UIControlEventValueChanged];

    

    

}

 

//滑动滑块时调用的方法

-(void)sliderEvent:(UISlider *)slide {

    NSLog(@"%f", slide.value);

}

 

 

//点击开关执行方法

-(void)swChange:(UISwitch *)swc {

    NSLog(@"");

    tf.enabled = swc.on;

}

 

 

-(void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

/*

#pragma mark - Navigation

 

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/

 

@end

 

转载于:https://my.oschina.net/VincentOSC/blog/829328

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值