我的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(@”你点我干嘛”);
}

posted on 2015-11-11 23:23  彩虹直至黑白  阅读(194)  评论(0编辑  收藏  举报

导航