//add a Label
UILabel *label=[[UILabelalloc]initWithFrame:CGRectMake(100,20, 150, 40)];
[label setText:@"i am a label "];
label.font=[UIFontsystemFontOfSize:20];
label.textAlignment=NSTextAlignmentLeft;
//文字内容自适应标签宽度
label.adjustsFontSizeToFitWidth=YES;
[self.viewaddSubview:label];
//add a button
UIButton *button=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100,300, 150, 40)];
[button setTitle:@"i am a button"forState:UIControlStateNormal];
//[button addTarget:selfaction:@selector(makeAnotherButton:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
//add a textField
UITextField *textField=[[UITextFieldalloc] initWithFrame:CGRectMake(100,150, 150, 40)];
//[textField setText:@"i am atextField"];
//只是显示password这个标识
textField.placeholder=@"password";
//密码编辑显示圆点PASSWORD
textField.secureTextEntry=YES;
//再次对textField编辑时清除内容
textField.clearsOnBeginEditing=YES;
//当编辑的时候才有clearButton
textField.clearButtonMode=UITextFieldViewModeWhileEditing;
//默认键盘
textField.keyboardType=UIKeyboardTypeDefault;
//边框样式 这个我觉得最好看
textField.borderStyle=UITextBorderStyleRoundedRect;
textField.textColor=[UIColorblueColor];
[self.viewaddSubview:textField];
版权声明:本文为博主原创文章,未经博主允许不得转载。