1.UIView
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view1.backgroundColor = [UIColor cyanColor];
[self.window addSubview:view1];
[view1 release];
[self.window bringSubviewToFront:view2];
[self.window sendSubviewToBack:view2];
view2.alpha = 0.5;
view3.tag = 100;
UIView *tempView = [self.window viewWithTag:100];
2.UILabel
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 150, 200)];
label.backgroundColor = [UIColor orangeColor];
[self.window addSubview:label];
label.text = @"fafdfasdfdasfdsa]";
label.numberOfLines = 3;
[label sizeToFit];
label.textAlignment = NSTextAlignmentCenter;
label.lineBreakMode = NSLineBreakByTruncatingMiddle;
label.textColor = [UIColor redColor];
label.shadowColor = [UIColor redColor];
label.shadowOffset = CGSizeMake(1, 2);
label.layer.borderWidth = 1;
label.layer.cornerRadius = 5;
label.layer.masksToBounds = YES;
label.font = [UIFont systemFontOfSize:20];
label.center = CGPointMake(150, 150);
[label release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(30, 50, 100, 30);
button.backgroundColor = [UIColor redColor];
[button setTitle:@"点我啊" forState:UIControlStateNormal];
[button setTitle:@"hehe" forState:UIControlStateHighlighted];
button.titleLabel.font = [UIFont systemFontOfSize:18];
button.layer.borderWidth = 0.1;
button.layer.cornerRadius = 10;
button.layer.masksToBounds = YES;
[self.window addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
button1.frame = CGRectMake(40, 40, 30, 30);
[button1 setBackgroundImage:[UIImage imageNamed:@"checked"] forState:UIControlStateNormal];
[self.window addSubview:button1];
[button1 addTarget:self action:@selector(chageImage:) forControlEvents:UIControlEventTouchUpInside];
self.isClick = NO;
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(120, 40, 51, 24);
[button2 setImage:[UIImage imageNamed:@"BtnOn"] forState:UIControlStateNormal];
button2.tag = 100;
[self.window addSubview:button2];
self.isSelected = YES;
[button2 addTarget:self action:@selector(chgngePic:) forControlEvents:UIControlEventTouchUpInside];
- (void)chageImage:(UIButton *)button
{
if (self.isClick) {
[button setBackgroundImage:[UIImage imageNamed:@"checked"] forState:UIControlStateNormal];
}
else{
[button setBackgroundImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
}
self.isClick = !self.isClick;
}
- (void)chgngePic:(UIButton *)button
{
if (self.isSelected) {
[button setImage:[UIImage imageNamed:@"BtnOff"] forState:UIControlStateNormal];
}
else{
[button setImage:[UIImage imageNamed:@"BtnOn"] forState:UIControlStateNormal];
}
self.isSelected = !self.isSelected;
}
4.UITextField
//输入框UITextFiled
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(40, 60, 200, 40)]
textField.backgroundColor = [UIColor redColor]
//加上圆角和边框,隐藏多余的部分
textField.layer.borderWidth = 1
textField.layer.cornerRadius = 5
label.layer.masksToBounds = YES
//UITextField系统提供的属性
textField.borderStyle = UITextBorderStyleRoundedRect
textField.text = @"zhangsan"
textField.textColor = [UIColor greenColor]
textField.textAlignment = NSTextAlignmentCenter
textField.font = [UIFont systemFontOfSize:20]
//占位符,当输入是消失
textField.placeholder = @"请输入密码"
//密文输入
textField.secureTextEntry = YES
textField.tag = 100
//textField的清除button
textField.clearButtonMode = UITextFieldViewModeWhileEditing
//改变键盘的类型
textField.returnKeyType = UIReturnKeySearch
textField.keyboardType = UIKeyboardTypeNumberPad
[self.window addSubview:textField]
[textField release]
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 40, 40)]
view.backgroundColor = [UIColor greenColor]
//弹出一个自定义视图,默认是键盘
textField.inputView = view
//给键盘添加一个辅助视图
textField.inputAccessoryView = view
//给textfield设置代理人
textField.delegate = self