Ios uitextfield显示,但按钮未显示

Ios uitextfield显示,但按钮未显示,ios,uibutton,Ios,Uibutton,将显示ui文本字段,但不会显示ui按钮。 如何显示按钮 UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(30.0, 150, 300, 30.0)]; password.delegate = self; [password setBorderStyle:UITextBorderStyleRoundedRect]; [password setClearButtonMode:UITextFieldViewMo

将显示
ui文本字段
,但不会显示
ui按钮
。 如何显示按钮

UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(30.0, 150, 300, 30.0)];
password.delegate = self;
[password setBorderStyle:UITextBorderStyleRoundedRect];
[password setClearButtonMode:UITextFieldViewModeAlways];
password.placeholder = @"Password";
[password setFont:[UIFont systemFontOfSize:10]];
[self.view addSubview:password];
//button
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(30, 200 , 50, 50)] ;
[button addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button = [UIButton buttonWithType: UIButtonTypeSystem];

 [self.view addSubview:button];

尝试添加按钮的
BackgroundColor
TitleColor

[button setBackgroundColor:[UIColor greenColor]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

您正在初始化按钮两次

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(30, 200 , 50, 50)] ;

button = [UIButton buttonWithType: UIButtonTypeSystem];
初始化系统按钮,稍后设置其框架

UIButton *button = [UIButton buttonWithType: UIButtonTypeSystem];
button.frame = CGRectMake(30, 200 , 50, 50);

希望这会有所帮助。

非常感谢您的帮助