UILabel text won't display

本小妞迷上赌 提交于 2019-12-11 13:54:28

问题


I'm having trouble in an iOS app I'm building with UILabels: despite initializing them the text I programmed won't show up and I'm at wits' end about what I should do.

For example, this is one of the app's screens in which I have this problem:

Welcome.m

@interface Welcome()

@end

@implementation Welcome

-(void) viewdidLoad{
    [super viewDidLoad];
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 47)];
    [self.view addSubview: label];
    label.text = @"Benvinguts a la pràctica de iOS I";
    label.numberOfLines = 4;

}

-(IBAction) buttonPressed: (id) sender
{

   [self performSegueWithIdentifier:@"Tutorial1" sender:self];
}


@end

Could you help me out in fixing this?


回答1:


You need to add a textColor:

   UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 47)];
    [self.view addSubview: label];
    label.text = @"Benvinguts a la pràctica de iOS I";
    label.numberOfLines = 4;
    label.textColor = [UIColor blackColor];



回答2:


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 47)];
[self.view addSubview: label];
label.text = @"Benvinguts a la pràctica de iOS I";
label.numberOfLines = 0;
[label SizeToFit];

You may use like this (label size manage by itself.)




回答3:


try this

UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 47)];
label.text = @"Benvinguts a la pràctica de iOS I";
label.numberOfLines = 4;
[self.view addSubview: label];

or maybe your label appears under the NavigationController. Try dropping below

 UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 140, 47)];


来源:https://stackoverflow.com/questions/23591326/uilabel-text-wont-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!