问题
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