1.UILabel
文本内容 text @"abc”
背景颜色 backgroundColor UIColor yellowColor
文本内容颜色 textColor UIColor redColor
文本对齐方式 textAlignment(枚举) NSTextAlignmentCenter
文本字体大小 font UIFont systemFontOfSize:20
文本行数 numberOfLines 0
自适应label尺寸 sizeToFit label sizeToFit
断行模式 lineBreakMode NSLineBreakByTruncatingMiddle
阴影颜色 shadowColor UIColor cyanColor
阴影大小 shadowOffset CGSizeMake(2, 1)
设置边框 layer.borderWidth 1
设置圆角 layer.cornerRadius 5
抹除圆角多余背景色 layer.masksToBounds YES
文本位置大小 label.frame CGRectMake(100, 100, 200, 200)
修改视图的位置 center CGPointMake(500, 175)
1.1创建UILabel
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 150)];
label.backgroundColor = [UIColor yellowColor];
[self.window addSubview:label];
[label release];
2.UIView
背景颜色 backgroundColor UIColor yellowColor
透明度 alpha 0.5
位置大小 frame CGRectMake(200, 100, 150, 150)
父视图把视图放在上面 bringSubviewToFront view2
父视图把视图放在下面 sendSubviewToBack view2
2.1创建UIView
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
view1.backgroundColor = [UIColor yellowColor];
[self.window addSubview:view1];
[view1 release];
3.UIButton
位置大小 frame CGRectMake(100, 100, 150, 70)
背景颜色 backgroundColor UIColor cyanColor
标题 setTitle: forState: @“确认" UIControlStateNormal
标题字体大小 titleLabel.font UIFont systemFontOfSize:25
圆角 layer.cornerRadius 10
边框 layer.borderWidth 1
点击方法 addTarget: action: forControlEvents:
self @selector(click:) UIControlEventTouchUpInside
背景图片 setBackgroundImage: forState:
[UIImage imageNamed:@"checked.png"] UIControlStateNormal
3.1创建UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 100, 40);
[self.window addSubview:button];
[button setTitle:@"确认" forState:UIControlStateNormal];
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;
[button addTarget:self action:@selector(changePic:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
-(void)changePic:(UIButton *)button{
}
4.UITextField
背景颜色 backgroundColor UIColor cyanColor
边框 layer.borderWidth 1
圆角 layer.cornerRadius 10
文本内容 text @"abc"
占位文本 placeholder @"占位字符"
文本颜色 textColor UIColor yellowColor
文本位置 textAlignment NSTextAlignmentCenter
密码圆点 secureTextEntry YES
键盘类型 keyboardType UIKeyboardTypeNumberPad
return样式 returnKeyType UIReturnKeySearch
清除按钮样式 clearButtonMode UITextFieldViewModeAlways
弹出视图.默认是键盘 inputView view
辅助视图 inputAccessoryView view
4.2创建UITextField
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200,40)];
textField.backgroundColor = [UIColor cyanColor];
[self.window addSubview:textField];
[textField release];
textField.delegate = self;
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
NSLog(@"测试return按钮");
//回收键盘 (改变第一响应者)
[textField resignFirstResponder];
return YES;
}
-(BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"测试清除按钮");
return YES;
}