为什么我的UILabel不更改? [英] Why isn't my UILabel being changed?

查看:106
本文介绍了为什么我的UILabel不更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的UILabel没有改变?我使用下面的代码,没有发生任何事情:

Why isn't my UILabel being changed? I am using the following code, and nothing is happening:

- (void)awakeFromNib {
    percentCorrect.adjustsFontSizeToFitWidth;
    percentCorrect.numberOfLines = 3;
    percentCorrect.minimumFontSize = 100;
}

这是我的Implemintation代码:

Here is my Implemintation code:

- (void) updateScore {
    double percentScore = 100.0 * varRight / (varWrong + varRight);
    percentCorrect.text = [NSString stringWithFormat:@"%.2f%%", percentScore];
}

- (void)viewDidLoad {
    percentCorrect.adjustsFontSizeToFitWidth = YES;
    percentCorrect.numberOfLines = 3;
    percentCorrect.minimumFontSize = 100;
    percentCorrect.text = @"sesd";
}


- (void)correctAns {
    numberRight.text = [NSString stringWithFormat:@"%i Correct", varRight];
}

-(void)wrongAns {
    numberWrong.text = [NSString stringWithFormat:@"%i Incorrect", varWrong];
}

#pragma mark Reset Methods
- (IBAction)reset:(id)sender; {
    NSString *message = @"Are you sure you would like to reset?";
    self.wouldYouLikeToReset = [[UIAlertView alloc] initWithTitle:@"Reset?" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
    [wouldYouLikeToReset addButtonWithTitle:@"Continue"];
    [self.wouldYouLikeToReset show];
    // Now goes to (void)alertView and see's what is being pressed!
}

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0)
    {
        NSLog(@"Cancel button pressed");
    }
    else
    {
        varRight = 0;
        varWrong = 0;
        [self wrongAns];
        [self correctAns];
        percentCorrect.text = [NSString stringWithFormat:@"0.0%%"];

    }
}

#pragma mark Button Action Methods

- (IBAction)right:(id)sender; {
    varRight++;
    [self correctAns];
    [self updateScore];
}

- (IBAction)wrong:(id)sender; {
    varWrong++;
    [self wrongAns];
    [self updateScore];
}


- (IBAction)subOneRight:(id)sender {
    if (varRight > 0 ) {
        varRight--;
        [self correctAns];
        [self updateScore];
    }
}


- (IBAction)subOneWrong:(id)sender {
    if (varWrong > 0) {
        varWrong--;
        [self wrongAns];
        [self updateScore];
    }
}

-(IBAction)addHalfCredit:(id)sender;
{
    varWrong++;
    varRight++;
    [self wrongAns];
    [self correctAns];
    [self updateScore];
}


@end


感谢

推荐答案


  1. adjustFontSizeToFitWidth 设置生效, numberOfLines 属性必须设置为1.如果它是!= 1,它不会工作。

  1. In order for the adjustsFontSizeToFitWidth setting to come into effect, the numberOfLines property must be set to 1. It won't work if it's != 1.

Are awakeFromNib viewDidLoad ,<$ c $

Are awakeFromNib, viewDidLoad, viewWillAppear being called at all?

minimumFontSize 属性将会如果文本适合当前字体与当前字体,则不执行任何操作。您是否为标签设置了字体属性?

The minimumFontSize property will do nothing if the text fits in the current bounds with the current font. Did you set the font property for the label?

percentCorrect.font = [UIFont systemFontOfSize:20];

最后,对于最小字体大小,不是 minimumFontSize = 100 有点太大了?

Finally, isn't a minimumFontSize = 100 a little too big for a min font size?

这篇关于为什么我的UILabel不更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆