//
// RootViewController.m
// UI17UISlider+UISwitch
//
// Created by focus on 2017/1/22.
// Copyright © 2017年 focus. All rights reserved.
//
#import "RootViewController.h"
@interface RootViewController ()
{
UITextField *tf;
}
@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