ios - Button Text not showing -


when try post following code, app shows empty rectangle button's text should be. beginner @ xcode , have determined code other tutorials.

- (void)viewdidload {     [super viewdidload];      uilabel *player1 = [[uilabel alloc]initwithframe:cgrectmake(35, 120,130, 30)];     [player1 settext:@"player"];     player1.layer.borderwidth = 1.0;     player1.layer.bordercolor = [uicolor blackcolor].cgcolor;      player1.textalignment = uitextalignmentcenter;     [self.view addsubview: player1];      uibutton *score1 = [[uibutton alloc]initwithframe:cgrectmake(165, 120, 60, 30)];     [score1 settitle:@"0" forstate:uicontrolstatenormal];     score1.layer.borderwidth = 1.0;     score1.layer.bordercolor = [uicolor blackcolor].cgcolor;     [self.view addsubview: score1];       uilabel *player2 = [[uilabel alloc]initwithframe:cgrectmake(35, 150, 130, 30)];     [player2 settext:@"opponent"];     player2.layer.borderwidth = 1.0;     player2.layer.bordercolor = [uicolor blackcolor].cgcolor;     player2.textalignment = uitextalignmentcenter;     [self.view addsubview: player2]; } 

like said, text in button showing up.

the reason why button looks blank because text color white. give different color , 0 show:

score1.layer.backgroundcolor = [uicolor blackcolor].cgcolor; 

enter image description here

if don't want change button background color, may want set text color:

[score1 settitlecolor:[uicolor bluecolor] forstate:uicontrolstatenormal]; 

read question: [initwithframe:frame] vs. [uibutton buttonwithtype], more creating uibutton these different methods.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -