2016-06-07 3 views
1

UITextField이 표시되지만 UIButton은 표시되지 않습니다. 버튼을 표시하려면 어떻게해야합니까 ?? BackgroundColor 버튼의 TitleColor를 추가 할 수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

보십시오 : 당신이 버튼을 두 번 intializing하는

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

감사합니다. –

0

.

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

희망이 도움이 될 것입니다.

관련 문제