標籤:
UIButton
1 //1.設定UIButton 的左右移動2 .center屬性 獲得 CGPoint 來修改x y3 //1.設定UIButton 的放大縮小4 bounds屬性 獲得CGRect 然後通過size.height設定高 wight設定寬
//3.或者使用frame 來設定空間的 移動以及大小
代碼建立一個UIButton
1 // 1.建立一個按鈕 2 UIButton *btn = [[UIButton alloc] init]; 3 4 // 2.添加按鈕 5 [self.view addSubview:btn]; 6 7 // 3.設定按鈕的frame 8 btn.frame = CGRectMake(100, 100, 100, 100); 9 10 // 4.給按鈕的預設狀態和高亮狀態設定背景圖片11 [btn setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal];12 [btn setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];13 14 // 5.給按鈕的預設狀態和高亮狀態分別設定文字和文字的顏色15 [btn setTitle:@"點我啊" forState:UIControlStateNormal];16 [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];17 18 [btn setTitle:@"摸我幹啥" forState:UIControlStateHighlighted];19 [btn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];20 21 // 6.給按鈕添加一個點擊事件,監控按鈕的點擊22 [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];23 24 25 26 - (void)btnClick:(UIButton *)btn27 {28 NSLog(@"btnClick");29 }
簡易動畫
1 //簡易動畫的建立有兩種方式 2 //1.頭尾式 3 [UIView beginAnimations : nil context:nil];//開啟動畫 4 [UIView setAnimationDuration:1];//設定動畫執行時間 5 //這裡寫入需要執行動畫的代碼 6 [UIView commitAnimations];//提交動畫 7 8 //2.Block式 9 [UIView animateWithDuration: 0.5 animations:^{10 11 //這裡寫入一個需要執行的動畫代碼12 }];
IOS(二)基本控制項UIButton、簡易動畫