2016-06-07 3 views
1

UITextField показан, но не UIButton. Как я могу показать кнопку?Отображается uitextfield, но кнопка не отображается

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]; 

ответ

1

Попробуйте добавить BackgroundColor и TitleColor кнопки:

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

СПАСИБО БОЛЬШЕ ЭТОЙ ПОМОЩИ –

0

вы кнопку intializing два раза.

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); 

Надеюсь, это поможет.

Смежные вопросы