UISwitch UIActivityIndicatorView UISegmentControl UIAlertView的使用网络
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor lightGrayColor]; /******UISwitch :开关****/ //开关大小是固定的,设置宽高不会影响它的大小 UISwitch *swith = [[UISwitch alloc]initWithFrame:CGRectMake(50, 50, 100, 100)]; //swith.backgroundColor = [UIColor lightGrayColor]; //设置当前开关是开的状态 swith.on = YES; //绑定事件 只有开/关两个状态,对应两个值,状态的改变意味着值在变化 [swith addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:swith]; /*******分段栏: UISegmentControl*********/ //UISegmentedControl *segment = [[UISegmentedControl alloc]initWithFrame:CGRectMake(50, 180, 100, 100)]; //初始化分栏的条目(标题) UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:@[@"电影",@"美食",@"娱乐"]]; segment.frame = CGRectMake(50, 180, 200, 50); //设置当前显示的栏目 segment.selectedSegmentIndex = 0; //绑定事件,监听当前栏目的跳转 [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:segment]; /******风火轮 :网络加载的提示*****/ //设置frame不会改变显示大小 UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(150, 50, 100, 100)]; //设置样式,系统提供三种样式(大白色,白色,灰色) indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; //只有开始转动才能够显示在屏幕上 [indicatorView startAnimating]; //[indicatorView stopAnimating]; [self.view addSubview:indicatorView]; /******UIAlertView*****/ UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"是否要保存修改" message:@"更改配置" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"肯定", nil]; //弹出视图,不须要加载,弹出视图的优先级比当前self.view要高 [alertView show]; } - (void)switchAction:(UISwitch *)swith { if (swith.on == YES) { NSLog(@"打开4G"); } } - (void)segmentAction:(UISegmentedControl *)segment { //事件发生,切换页面/栏目 NSLog(@"%ld",segment.selectedSegmentIndex); //--> 切换页面 } #pragma mark - UIAlertViewDelegate - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSLog(@"%ld",buttonIndex); }