这周我们学习了UI,下面是我的一些学习笔记:
//获得屏幕满屏时的数值
CGRect rect = [UIScreen mainScreen].bounds;
//创建一个Window让他显示在屏幕上
self.window = [[UIWindow alloc ]initWithFrame:rect];
//设置window的背景颜色
self.window.backgroundColor = [UIColor lightGrayColor];
//把当前的window作为主window让它显示出来
[self.window makeKeyAndVisible];
/****************** UIButton***********************/
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(20, 40, 100, 30);
//设置高亮状态下按钮的标题
[button setTitle:@"按钮" forState:UIControlStateNormal];
//设置点击事件响应的方法
[button addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];
//设置平常状态下标题的颜色
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//设置高亮状态下标题的颜色
[button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
//设置标题的字体
button.titleLabel.font = [UIFont systemFontOfSize:14];
//添加到window上
[self.window addSubview:button];
/******************** UITextField 的常用属性 *********************/
UITextField *textfield = [[UITextField alloc]initWithFrame:CGRectMake(200, 200, 100, 25)];
//禁止首字母大写
textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
//设置键盘类型
textfield.keyboardType = UIKeyboardTypeNamePhonePad;
//输入框的边框类型
textfield.borderStyle = UITextBorderStyleRoundedRect;
//textfield.borderStyle = UITextBorderStyleLine;
//textfield.borderStyle = UITextBorderStyleBezel;
//textfield.borderStyle = UITextBorderStyleNone;
//设置委托代理模式
// textfield.delegate = self;
//键盘上得return按钮
textfield.returnKeyType = UIReturnKeyDone;
//是否安全输入,是的话,输入内容将为*号
textfield.secureTextEntry = NO;
//清除按钮模式
textfield.clearButtonMode = UITextFieldViewModeAlways;
//输入框中的文本颜色
textfield.textColor = [UIColor redColor];
//输入框的字体
textfield.font = [UIFont boldSystemFontOfSize:14];
//添加到window上
[self.window addSubview:textfield];