UILabel * nameLabel = [[UILabel alloc]init];
//定位label(x,y,长,高)
nameLabel.frame = CGRectMake(10, 100, 100, 30);
nameLabel.text = @"Ios30班";
nameLabel.textColor = [UIColor redColor];//设置字体
nameLabel.backgroundColor = [UIColor yellowColor];//背景颜色
nameLabel.textAlignment = UITextAlignmentCenter;//对齐方式
//加入一个view
[self.window addSubview:nameLabel];
[nameLabel release];
// UITextField
UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 140, 100, 30)];
textField.delegate = self;//键盘回收需要代理
//边框样式
textField.borderStyle = UITextBorderStyleRoundedRect;
//键盘样式
textField.keyboardType = UIKeyboardTypeAlphabet;
textField.returnKeyType = UIReturnKeyDefault;//把键盘的return 换成Done
textField.clearButtonMode = UITextFieldViewModeAlways;//添加清空输入的按钮
[self.window addSubview:textField];
[textField release];
//UIbutton
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];//设置button形状
[btn setFrame:CGRectMake(100, 100, 100, 30)];
[btn setTitle:@"123" forState:UIControlStateNormal];//设置Button标题
[btn setTitle:@"456" forState:UIControlStateHighlighted];//
//事件 点击不放时候的状态
[btn addTarget:self
action:@selector(doAction)
forControlEvents:UIControlEventTouchUpInside];//触发方式
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];//键盘回收
return YES;
}
UIView 那些事
最新推荐文章于 2020-11-11 13:50:39 发布