(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UISegmentedControl *segement = [[UISegmentedControl alloc] initWithItems:@[@”小学”,@”初中”,@”高中”]];
segement.frame = CGRectMake(100, 200, 200, 40);
[self.view addSubview:segement];
//设置颜色
segement.tintColor = [UIColor redColor];
//设置标题
[segement setTitle:@”大学” forSegmentAtIndex:2];
//设置图片
[segement setImage:[UIImage imageNamed:@”bj_top_jt@2x”] forSegmentAtIndex:0];
//插入标题
[segement insertSegmentWithTitle:@”高中” atIndex:2 animated:YES];
//插入图片
[segement insertSegmentWithImage:[UIImage imageNamed:@”Fav_Filter_ALL_HL@2x”] atIndex:4 animated:YES];
//移除内容
[segement removeSegmentAtIndex:4 animated:YES];
// [segement removeAllSegments];
//事件处理
//除了button之外所有的点击控件都用UIControlEventValueChanged触发
[segement addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
}
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(100, 200, 200, 30)];
//设置最小值
slider.minimumValue = 100;
//设置最大值
slider.maximumValue = 1000;
//设置滑过的颜色
slider.minimumTrackTintColor = [UIColor redColor];
//设置未滑过的颜色
slider.maximumTrackTintColor = [UIColor greenColor];
//设置滑块按钮的颜色
slider.thumbTintColor = [UIColor blackColor];
//添加事件
[slider addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
}
(void)changeValue:(UISlider *)slider
{
//当前value
NSLog(@”slider == %g”,slider.value);
}
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UISwitch *swth = [[UISwitch alloc] initWithFrame:CGRectMake(100, 200, 100, 30)];
//设置开的颜色
// swth.onTintColor = [UIColor redColor];
//设置滑块的颜色
// swth.thumbTintColor = [UIColor blackColor];
swth.on = YES;
//添加事件
[swth addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:swth];
}
(void)valueChange:(UISwitch *)swth
{
if (swth.isOn) {
NSLog(@”开”);
}else
{
NSLog(@”关”);
}
}
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activity.frame = CGRectMake(100, 200, 100, 50);
//开始转动
[activity startAnimating];
//设置颜色
activity.color = [UIColor redColor];
[self.view addSubview:activity];
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UIProgressView *progress = [[UIProgressView alloc] initWithFrame:CGRectMake(50, 200, 300, 50)];
//未走过的颜色
progress.trackTintColor = [UIColor redColor];
//走过的颜色
progress.progressTintColor = [UIColor greenColor];
[self.view addSubview:progress];
//计时器让进度条走
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(progress:) userInfo:progress repeats:YES];
}
(void)progress:(NSTimer *)time
{
UIProgressView progress2 = (UIProgressView )time.userInfo;
//progress2.progress当前进度条的值
[progress2 setProgress:progress2.progress+0.1 animated:YES];
//进度条最大值为1
if (progress2.progress == 1) {
if ([time isValid]) {
[time invalidate];
}
}
}
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sheetShow)];
[self.view addGestureRecognizer:tap];
}
(void)sheetShow
{
//参数1:主标题 默认是灰色
//参数2:代理对象
//参数3:取消按钮
//参数4:副标题 默认是红色
//参数5:其他标题 蓝色
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@”取消” destructiveButtonTitle:nil otherButtonTitles:@”上海”,@”北京”,@”杭州”, nil];
[sheet showInView:self.view];
}
(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@”buttonIndex == %ld”,buttonIndex);
NSLog(@”title == %@”,[actionSheet buttonTitleAtIndex:buttonIndex]);
}
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(alertShow)];
[self.view addGestureRecognizer:tap];
}
(void)alertShow
{
//参数1:主标题
//参数2:发送的信息
//参数3:代理对象
//参数4:取消按钮
//参数5:其他按钮
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”英雄联盟” message:@”您的账号已被封” delegate:self cancelButtonTitle:@”取消” otherButtonTitles:@”确定”, nil];
[alert show];
}
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@”index == %ld”,buttonIndex);
// if (buttonIndex == 0) {
//
// }else
// {
//
// }
NSLog(@”title == %@”,[alertView buttonTitleAtIndex:buttonIndex]);
}
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
_label = [[UILabel alloc] initWithFrame:CGRectMake(50, 190, 50, 50)];
_label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:_label];
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 200, 100, 50)];
[stepper addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
// stepper.tintColor = [UIColor redColor];
[self.view addSubview:stepper];
}
(void)changeValue:(UIStepper *)stepper
{
//当前值
NSLog(@”value == %g”,stepper.value);
//步进数
NSLog(@”stepValue == %g”,stepper.stepValue);
_label.text = [NSString stringWithFormat:@”%g”,stepper.value];
}