iphone - UILabel 文本错误

标签 iphone objective-c ios uilabel

我正在使用 UILabel 来显示我的分数和我的高分,但是当分数标签进入四重摘要时它会显示“分数:10 ...”,但高分标签不会这样做。

这里是标签的初始化代码(标签后面带1的显示文字,不带1的标签显示实际数字):

//SET UP THE SCORE LABEL HERE scoreLabelWidth = 100; scoreLabelPos = 260;

scoreLabel = [[UILabel alloc] init];
[scoreLabel setFont: [UIFont fontWithName: @"TimesNewRoman" size: 10.0f]];
[scoreLabel setFrame: CGRectMake(260, scoreLabelPos, scoreLabelWidth, 40)];
[scoreLabel setBackgroundColor:[UIColor clearColor]];
[scoreLabel setTextColor: [UIColor clearColor]];
[scoreLabel setTextColor: [UIColor whiteColor]];
scoreLabel.transform = CGAffineTransformMakeRotation(89.53);
[self addSubview: scoreLabel];

scoreLabel1 = [[UILabel alloc] init];
[scoreLabel1 setFont: [UIFont fontWithName: @"TimesNewRoman" size: 10.0f]];
[scoreLabel1 setFrame: CGRectMake(262, 230, 100, 40)];
[scoreLabel1 setBackgroundColor:[UIColor clearColor]];
[scoreLabel1 setTextColor: [UIColor clearColor]];
[scoreLabel1 setTextColor: [UIColor whiteColor]];
scoreLabel1.transform = CGAffineTransformMakeRotation(89.53);
[self addSubview: scoreLabel1];

highScoreLabel = [[UILabel alloc] init];
[highScoreLabel setFont: [UIFont fontWithName: @"TimesNewRoman" size: 10.0f]];
[highScoreLabel setFrame: CGRectMake(262, 150, 100, 40)];
[highScoreLabel setBackgroundColor:[UIColor clearColor]];
[highScoreLabel setTextColor: [UIColor clearColor]];
[highScoreLabel setTextColor: [UIColor whiteColor]];
highScoreLabel.transform = CGAffineTransformMakeRotation(89.53);
[self addSubview: highScoreLabel];

highScoreLabel1 = [[UILabel alloc] init];
[highScoreLabel1 setFont: [UIFont fontWithName: @"TimesNewRoman" size: 10.0f]];
[highScoreLabel1 setFrame: CGRectMake(262, 50, 100, 40)];
[highScoreLabel1 setBackgroundColor:[UIColor clearColor]];
[highScoreLabel1 setTextColor: [UIColor clearColor]];
[highScoreLabel1 setTextColor: [UIColor whiteColor]];
highScoreLabel1.transform = CGAffineTransformMakeRotation(89.53);
[self addSubview: highScoreLabel1];

然后在我的更新部分中,我为标签设置了文本和字符串格式(如果您需要该代码,请告诉我)

谢谢!

最佳答案

更改您正在使用的标签的 lineBreakMode 属性。默认情况下,它设置为 UILineBreakModeTailTruncation,这会导致您看到的行为。

或者,您可以将 adjustsFontSizeToFitWidth 属性设置为 YES,以允许标签自动减小字体大小。如果这样做,最好也将 minimumFontSize 属性设置为合理的值。例如:

scoreLabel.adjustsFontSizeToFitWidth = YES;
scoreLabel.minimumFontSize = 6.0f;

关于iphone - UILabel 文本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12032755/

相关文章:

iphone - 使用 Apple 代码签名为 Cydia 构建应用程序

iOS:一般从 NSObject 类序列化/反序列化复杂的 JSON

objective-c - 协议(protocol)对象 : Compiler Warnings on addObserver: 上的键值观察

ios - ITMS-90809 : Deprecated API Usage -- Apple will stop accepting submissions of apps that use UIWebView APIs

iphone - 如何在设备上更改 iOS 应用程序的文件名?

iphone - 从数据库检索数据到不同的 View Controller

ios - 过滤字典数组时无法解析格式字符串?

ios - 无法创建 UIManagedDocument

ios - Alamofire - 在 responseJSON 之前预处理响应

iphone - 我可以将 UITableView 分组背景图案用于 UIView 吗?