【问题标题】:UILabel text errorUILabel 文本错误
【发布时间】:2012-08-20 05:44:14
【问题描述】:

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

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

//在此处设置分数标签 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];

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

谢谢!

【问题讨论】:

  • 请提供更新文本的代码
  • 让标签变宽,以便显示完整的数字...

标签: iphone objective-c ios uilabel


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-08-30
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多