2016-06-07 95 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); 

希望這會有所幫助。