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); }