1.
UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0 , 111, 111);
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"button_down.png"] forState:UIControlStateHighlighte
d];
[button setTitle:@"按钮的名字" forState:UIControlStateNormal];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 1, -8)];//文字的位置
button.contentHorizontalAlignme
nt = UIControlContentHorizont
alAlignmentLeft;
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpIns
ide];
[self.view addSubview:button];
2. UITextField
UITextField *_textFi
eld = [[UITextField alloc] initWithFrame:CGRectMake(0, 0 , 111, 30)];
_
textFi
eld.borderStyle = UITextBorderStyleRounded
Rect;
_
textFi
eld.contentVerticalAlignment
= UIControlContentVertical
AlignmentCenter;//垂直居中
_
textFi
eld.font = [UIFont boldSystemFontOfSize:16];
_
textFi
eld.placeholder = @"6~12位字符";//默认显示的底纹字
_
textFi
eld.text = @"";
_
textFi
eld.returnKeyType = UIReturnKeyDone;//键盘上多功能键的名字
_
textFi
eld.secureTextEntry = YES;//加密
_
textFi
eld.clearButtonMode = UITextFieldViewModeWhile
Editing;//清除的X号按钮
[self.view addSubview:_
textFi
eld];
_
textFi
eld.delegate = self;
[_
textFi
eld release];
常用的委托:
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//键盘上的多功能按键
}
2. UITextField
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//键盘上的多功能按键
}