我的iOS學習歷程 - UITextField UIButton

UITextField

1.初始化
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];

2佔位字 placeholder(只有當沒有輸入的字 纔會顯示)
textField.placeholder = @”請輸入用戶名”;

3 clearsOnBeginEditing
textField.clearsOnBeginEditing = YES;

4.是否允許輸入 enabled(默認是YES:可以輸入)
textField.enabled = YES;

5.密文輸入 secureTextEntry
textField.secureTextEntry = YES;

6 彈出鍵盤的類型 keyboardType
textField.keyboardType = UIKeyboardTypeDefault;

7彈出鍵盤右下角return按鈕 類型 returnKeyType
textField.returnKeyType = UIReturnKeyNext;

8自定義鍵盤 inputView(只有高度可以影響, 其他值不影響)
UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)];

9鍵盤輔助視圖 inputAccessoryView
UIView *inputAccessoryView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];

10邊框樣式 borderStyle
textField.borderStyle = UITextBorderStyleRoundedRect;

11刪除按鈕 何時存在 clearButtonMode(默認是用不出現的)
textField.clearButtonMode = UITextFieldViewModeUnlessEditing;

12輸入框左視圖 leftView(只有長度和高度可以影響)
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

13左視圖何時存在 leftViewMode
textField.leftViewMode = UITextFieldViewModeWhileEditing;

14輸入框右視圖 rightView
UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];

15設置代理(方法在哪裏實現的 就把誰設置爲代理)
textField.delegate = self;

16實現協議中的方法(textFieldShouldReturn)
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
// 實現鍵盤迴收(收回textField的第一響應者 點擊哪個哪個就是第一響應者)
// 取消第一響應者 resignFirstResponder
[textField resignFirstResponder];
return YES;
}

UIButton

17初始化Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

18設置某個狀態下的標題 setTitle:NSString* forState:(UIControlState)
[button setTitle:@”普通” forState:(UIControlStateNormal)];
[button setTitle:@”高亮” forState:(UIControlStateHighlighted)];
[button setTitle:@”選中” forState:(UIControlStateSelected)];

19給Button添加一個方法 addTarget:self action:@selector(方法) forControlEvents:(UIControlEvents(點擊狀態))
[button addTarget:self action:@selector(buttonClick:)

20給某狀態下的標題設置顏色
[button setTitleColor:[UIColor yellowColor] forState:(UIControlStateNormal)];
[button setTitleColor:[UIColor blueColor] forState:(UIControlStateHighlighted)];
[button setTitleColor:[UIColor greenColor] forState:(UIControlStateSelected)];

21.// 創建一張圖片(如果不是png格式的圖片 需要把後綴加上)
UIImage *imageNormal = [UIImage imageNamed:@”Normal”];

22 給Button添加前景圖片(圖多大就佔多大 標題會被擠一邊去)
[button setImage:(imageNormal) forState:(UIControlStateNormal)];

23.給Button添加背景圖片
[button setBackgroundImage:imageNormal forState:(UIControlStateNormal

24給button 添加的方法
- (void)buttonClick:(UIButton *)button {
// 更改一下選中的狀態
button.selected = !button.selected;
NSLog(@”你點我幹嘛”);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章