当前位置:  开发笔记 > 编程语言 > 正文

为什么我的UILabel没有改变?

如何解决《为什么我的UILabel没有改变?》经验,为你挑选了1个好方法。

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

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

这是我的Implemintation代码:

- (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> ettore..:

    为了使adjustsFontSizeToFitWidth设置生效,numberOfLines必须将属性设置为1.如果它是!= 1将无效.

    awakeFromNib,viewDidLoad,viewWillAppear被称为呢?

    minimumFontSize如果文本与当前字体匹配当前边界,则该属性将不执行任何操作.您是否为标签设置了font属性?

    percentCorrect.font = [UIFont systemFontOfSize:20];

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


这是正确的答案.adjustsFontSizeToFitWidth属性的UILabel类引用声明"仅当numberOfLines属性设置为1时,此属性才有效".
推荐阅读
勤奋的瞌睡猪_715
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有