效果
特点
1).都是系统自己的控件,只是做一个基础知识的归纳总结
源码
github:https://github.com/makingitbest/OtherViews
细节
1.UISwitch
#import "ViewController_0.h"
@interface ViewController_0 ()
@end
@implementation ViewController_0
- (void)viewDidLoad {
[super viewDidLoad];
// initWithFrame 并不能调整按钮的大小,只能设置它的位置.
UISwitch *swtch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 150, 100, 100)];
swtch.tintColor = [UIColor redColor]; // 关闭状态下的颜色
swtch.onTintColor = [UIColor blueColor]; // 打开状态下的颜色
swtch.thumbTintColor = [UIColor brownColor]; // 滑块颜色
[swtch setOn: YES]; //设置打开按钮,显示的是打开状态的颜色;事实上默认是关闭按钮
[self.view addSubview:swtch];
swtch.onImage = [UIImage imageNamed:@"onimage"]; //在没有设置onTintColor的时候有效,其他事件无效
swtch.offImage = [UIImage imageNamed:@"onimage"]; //在没有设置tintColor的时候有效,其他事件无效
}
@end
2.UISlider
#import "ViewController_1.h"
@interface ViewController_1 ()
@property (nonatomic, strong) UILabel *label;
@end
@implementation ViewController_1
- (void)viewDidLoad {
[super viewDidLoad];
// 滑动按钮的大小没法改变
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 250, 220, 50)];
slider.minimumValue = 0;
slider.maximumValue = 10;
[slider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
slider.layer.borderWidth = 1;
self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 50)];
self.label.backgroundColor = [UIColor yellowColor];
self.label.text = @"监控slider";
[self.view addSubview:self.label];
}
- (void)valueChanged:(UISlider *)slider {
self.label.text = [NSString stringWithFormat:@"%.2f",slider.value];
}
@end
3.UIProgressView
#import "ViewController_2.h"
@interface ViewController_2 ()
@property (nonatomic, strong) UIProgressView *progressView;
@property (nonatomic, strong) NSTimer *timer;
@end
@implementation ViewController_2
- (void)viewDidLoad {
[super viewDidLoad];
// 不能设置 progressView 的高度
self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(50, 100, 220, 40)];
self.progressView.trackTintColor = [UIColor grayColor];
self.progressView.progressTintColor = [UIColor greenColor];
[self.view addSubview:self.progressView];
self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(scheduledTimer:) userInfo:nil repeats:YES];
}
- (void)scheduledTimer:(NSTimer *)timer {
self.progressView.progress += 0.5;
}
@end
4.UIAlertController
#import "ViewController_3.h"
typedef enum : NSUInteger {
kButtonStyleOne,
kButtonStyleTwo,
kButtonStyleThree,
} EViewController_3;
@interface ViewController_3 ()
@property (nonatomic, strong) UIButton *buttonStyle1;
@property (nonatomic, strong) UIButton *buttonStyle2;
@property (nonatomic, strong) UIButton *buttonStyle3;
@property (nonatomic, strong) UIAlertAction *secureTextAlertAction;
@end
@implementation ViewController_3
- (void)viewDidLoad {
[super viewDidLoad];
self.buttonStyle1 = [[UIButton alloc] initWithFrame:CGRectMake(10, 80, 200, 50)];
self.buttonStyle1.backgroundColor = [UIColor grayColor];
self.buttonStyle1.tag = kButtonSt