IOS UI 代码创建UIButton,UITextField,UILabel
? ??//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;
??? //文字內(nèi)容自適應(yīng)標簽寬度
??? 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編輯時清除內(nèi)容
??? textField.clearsOnBeginEditing=YES;
??? //當編輯的時候才有clearButton
??? textField.clearButtonMode=UITextFieldViewModeWhileEditing;
??? //默認鍵盤
??? textField.keyboardType=UIKeyboardTypeDefault;
? ?//邊框樣式 這個我覺得最好看
??? textField.borderStyle=UITextBorderStyleRoundedRect;
??? textField.textColor=[UIColorblueColor];
??? [self.viewaddSubview:textField];
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
轉(zhuǎn)載于:https://www.cnblogs.com/yuqingzhude/p/4836552.html
總結(jié)
以上是生活随笔為你收集整理的IOS UI 代码创建UIButton,UITextField,UILabel的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 听过最好听的宠物名字
- 下一篇: 求常回家看看歌词!