- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
UIViewController *vc = [[UIViewControlleralloc] init];
self.window.rootViewController = vc;
[vc release];
[self.windowrelease];
// 标签
UILabel *lable = [[UILabelalloc] initWithFrame:CGRectMake(0,20, 300, 40)];
lable.backgroundColor = [UIColorblackColor];
// 设置文本
lable.text =@"男神最帅pppppppppppppppppppppppppppppppppppppppppppppppqweeeeeeeeeeeeeepppppppqqqqqqqqqqqqqqqqqqqqqqqqqq";
// 设置字体颜色
lable.textColor = [UIColoryellowColor];
// 设置字体大小
lable.font = [UIFontsystemFontOfSize:20];
// 文本的对其方式
lable.textAlignment =NSTextAlignmentCenter;
// 行数
lable.numberOfLines = 2;
// 断行方式
lable.lineBreakMode =NSLineBreakByTruncatingMiddle;
// 阴影颜色
lable.shadowColor = [UIColorredColor];
// 阴影大小
lable.shadowOffset = CGSizeMake(5, 5);
// 设置标记
lable.tag = 1001;
[self.windowaddSubview:lable];
[lable release];
// 文本输入框
UITextField *textField = [[UITextFieldalloc] initWithFrame:CGRectMake(0,70, self.window.frame.size.width,20)];
textField.backgroundColor = [UIColorredColor];
[self.windowaddSubview:textField];
// 边框风格
textField.borderStyle =UITextBorderStyleBezel;
// 设置占位符
textField.placeholder = @"haha";
// 设置标记
textField.tag = 1002;
// 获取文本输入框输入内容
// textField.text;
// 设置输入文字的颜色
textField.textColor = [UIColorwhiteColor];
// 文本对其方式和 文本大小与UILable设置的方法相同
// 是否允许输入
// NO - 不允许输入
textField.enabled = YES;
// 是否开始输入的时候清空输入框内容
textField.clearsOnBeginEditing =YES;
UITextField *textField1 = [[UITextFieldalloc] initWithFrame:CGRectMake(0,100, self.window.frame.size.width,20)];
textField1.backgroundColor = [UIColorredColor];
textField1.textColor = [UIColorgreenColor];
[self.windowaddSubview:textField1];
// 是否以圆点格式输入(密码)
textField.secureTextEntry = YES;
// 设置键盘风格
textField.keyboardType =UIKeyboardTypeNumberPad;
// 键盘右下角按钮类型
textField.returnKeyType = UIReturnKeyGoogle;
UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(0,0, 300, 200)];
view.backgroundColor = [UIColorblueColor];
// 自定义输入试图(默认是键盘
// 多数使用自定义键盘
textField1.inputView = view;
// borderStyle - 边框样式(枚举值)
textField1.borderStyle =UITextBorderStyleLine;
// clearButtonMode - 清除按钮模式(枚举值)
// leftView - 输入框左视图
// leftViewMode - 左视图的显示模式
// rightView - 输入框右视图
// rightViewMode - 右视图的显示模式
// 图片显示
UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(0,130, self.window.frame.size.width,self.window.frame.size.width -100)];
[self.windowaddSubview:imageView];
// 设置图片
imageView.image = [UIImageimageNamed:@"2.jpg"];
imageView.contentMode =UIViewContentModeScaleAspectFill;
// 控件
UIButton *butten = [UIButtonbuttonWithType:UIButtonTypeCustom];
butten.frame = CGRectMake(0, 400, self.window.frame.size.width,30);
butten.backgroundColor = [UIColorpurpleColor];
// 按钮设置标题
// 参数1:按钮标题
// 参数2:显示这个标题的状态
[butten setTitle:@"点我"forState:UIControlStateNormal];
[butten setTitle:@"asdas"forState:UIControlStateSelected];
// 添加点击事件
[butten addTarget:selfaction:@selector(buttonDidPress:)forControlEvents:UIControlEventTouchUpInside];
[self.windowaddSubview:butten];
[imageView release];
[view release];
[textField release];
[textField1 release];
return YES;
}
- (void)buttonDidPress:(UIButton *)sender {
UILabel *label = [self.windowviewWithTag:1001];
UITextField *textField = [self.windowviewWithTag:1002];
label.text = textField.text;
// 取消键盘的方式
// 取消第一响应
[textField resignFirstResponder];
}