标签UILabel
//创建一个标签,给定位置大小
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 300, 40)];
label.backgroundColor = [UIColor redColor];//背景颜色
// 设置文字
label.text = @"男神";
// 设置字体颜色
label.textColor = [UIColor whiteColor];
// 设置字体和大小
label.font = [UIFont systemFontOfSize:40];
//文本的对齐方式(水平方向)
label.textAlignment = NSTextAlignmentCenter;//居中
//NSTextAlignmentLeft 居左
//NSTextAlignmentLeft 居右
// 控制文本行数
label.numberOfLines = 3;
// 断行模式
label.lineBreakMode = NSLineBreakByCharWrapping;
// 阴影颜色
label.shadowColor = [UIColor greenColor];
// 阴影大小
label.shadowOffset = CGSizeMake(5, 5);
label.tag = 1001;//设置一个tag值
[self.window addSubview:label];//别忘记添加到视图上哟
文本输入框UITextField
// 文本输入框
//创建一个 UITextField
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 70, self.window.frame.size.width, 20)];
// 设置边框
textField.borderStyle = UITextBorderStyleRoundedRect;
// 设置占位符
textField.placeholder = @"Hello";
textField.backgroundColor = [UIColor cyanColor];//背景颜色
[self.window addSubview:textField];//添加到视图
// 获取文本输入框的输入内容
// textField.text;
// 设置输入文字的颜色
textField.textColor = [UIColor grayColor];
// 文本对齐方式和大小与uilabel 设置方法相同
// 是否允许输入 no - 不允许
textField.enabled = YES;
// 是否开始输入时清空输入内容
textField.clearsOnBeginEditing = YES;
// 是否以圆点格式显示(适用于密码)
textField.secureTextEntry = YES;
// 设置键盘风格
// textField.keyboardType = UIKeyboardTypeNumberPad;
// 键盘右下角按钮类型
textField.returnKeyType = UIReturnKeyJoin;
//自定义输入视图(默认是键盘)
// 多数使用在自定义键盘
// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
// view.backgroundColor = [UIColor blackColor];
// textField.inputAccessoryView = view;
// 边框样式(枚举值) - borderstyle
//
// clearButtonMode - 清除按钮模式(枚举值)
//
// leftView - 输入框左视图
//
// leftViewMode - 左视图的显视模式
//
// rightView - 输入框右视图
//
// rightViewMode - 右视图的显示模式
// 取消键盘方式
// 取消第一响应
[textField resignFirstResponder];
UIimage 图片
// 图片显示
//初始化
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 300, self.window.frame.size.width, self.window.frame.size.width)];
// 设置图片
iv.image = [UIImage imageNamed:@"瑜.png"];//
// 设置图片比例的问题
iv.contentMode = UIViewContentModeScaleAspectFill;
[self.window addSubview:iv];//添加到视图
按钮UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// button.layer.corner.cliptobound;
button.frame = CGRectMake(20, 400, 200, 30);
button.backgroundColor = [UIColor purpleColor];
[self.window addSubview:button];
// 按钮设置标题
// 参数1 :按钮的标题
// 参数2 :显示这个标题的状态
[button setTitle:@”点我点我” forState:UIControlStateNormal];
//UIControlStateHighlighted UIControlStateDisabled
// 添加点击事件
[button addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
//点击事件
- (void)buttonDidPress:(UIButton *)sender {
//可以添加点击动作
}