UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(20,40,80,30)];
// 背景颜色
label.backgroundColor = [UIColorgreenColor];
// 添加文字
label.text =@"神剑";
// 文字对齐方式
label.textAlignment =NSTextAlignmentCenter;
// 文字颜色
label.textColor = [UIColorblackColor];
// 字体
label.font = [UIFontsystemFontOfSize:20];
// 设置文字行数
label.numberOfLines =2;
// 设置边框圆角
label.layer.cornerRadius =5;
// 设置边框 宽度为3
label.layer.borderWidth =3;
// 边框颜色
label.layer.borderColor = [UIColorblueColor].CGColor;
// 设置阴影
label.shadowColor = [UIColorredColor];
// 阴影大小
label.shadowOffset =CGSizeMake(2.0,2.0);
// 文字可变 默认为YES
label.enabled =NO;
// 用户交互
label.userInteractionEnabled =YES;
label.transform = CGAffineTransformMakeRotation(0.5); //设置label的旋转角度
[_windowaddSubview:label];
[labelrelease];
UIView *view = [[UIViewalloc]initWithFrame:CGRectMake(40,90,80,30)];
view.backgroundColor = [UIColorgreenColor];
// 设置中心点
// view.frame = CGRectMake(0, 0, 80, 30);
// view.center = CGPointMake(100, 100);
// 隐藏
view.hidden =YES;
// 透明度
view.alpha =0.5;// 0.1 ~ 1
[_windowaddSubview:view];
// 视图置顶
[_windowbringSubviewToFront:view];
// 视图置底
[_windowsendSubviewToBack:view];
// 交换两个视图
// [_window exchangeSubviewAtIndex:<#(NSInteger)#> withSubviewAtIndex:<#(NSInteger)#>]
// 插入视图
// _window insertSubview:<#(UIView *)#> atIndex:<#(NSInteger)#>
// 移除视图
[view removeFromSuperview];
// 判断一个视图是否是另一个的子视图
[view isDescendantOfView:_window];
[viewrelease];
UITextField *textField = [[UITextFieldalloc]initWithFrame:CGRectMake(0,0,200,40)];
// 提示输入 textField输入后消失
textField.placeholder =@"请输入";
// 设置边框样式
textField.borderStyle =UITextBorderStyleRoundedRect;
// 右侧清除按钮
textField.clearButtonMode =UITextFieldViewModeWhileEditing;
// 隐藏输入信息一般用在密码输入
textField.secureTextEntry =YES;
// Button初始化需要先选择样式
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
// 设置frame
button.frame =CGRectMake(20,20,50,50);
// 设置背景颜色
button.backgroundColor = [UIColorblueColor];
// 设置按钮标题
[button setTitle:@"按钮"forState:UIControlStateNormal];
// 设置标题颜色(标题默认为蓝色)
[button setTitleColor:[UIColorwhiteColor]forState:UIControlStateNormal];
// 设置标题字体大小
// 加粗字体为 boldSystemFontOfSize
[button.titleLabelsetFont:[UIFontsystemFontOfSize:20]];
// button 点击事件
[button addTarget:selfaction:@selector(buttonDidPress:)forControlEvents:UIControlEventTouchUpInside];
- (void)buttonDidPress:(UIButton *) button {
button.backgroundColor = [UIColor greenColor];
}
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
// 设置图像 UIImage
// 在设置图片的时候名称+后缀 一定要全部写上,只有.png可以忽略不写
imageView.image = [UIImageimageNamed:@"/Users/dllo/Desktop/[(ITVEW13E5N}HL~[4Q$4%8.jpg"];
// 填充方式
imageView.contentMode =UIViewContentModeScaleAspectFill;
// 圆角
imageView.layer.masksToBounds =YES;
imageView.layer.cornerRadius =50;