Search code examples
iosiphonefontscocos2d-iphonesize

Trying to change the size of a font in my iPhone game and getting this error


I have the following where I am trying to get this label in large fonts. I am doing the following:

myScoreLabel.string = [NSString stringWithFormat:@"Score: %d", totalPointsPlayer];
myScoreLabel.fontName = [UIFont fontWithName:@"Arial" size:30];

I get this error: Incompatible pointer types assigning NSString *'from UIFont *'

Is their a way to change another way to change the size of the font? Thanks I am somewhat new to Objective C coding and I am trying to learn while building a tiny game. Thanks in advance.


Solution

  • UILabel does not provide a string or a fontName property. Try ...

    myScoreLabel.text = [NSString stringWithFormat:@"Score: %d", totalPointsPlayer];
    myScoreLabel.font = [UIFont fontWithName:@"Arial" size:30];
    

    EDIT - Understand now that this is a cocos2d control. I have limited experience with it, but a glance at the docs for CCTLabelTTF indicates that fontName is an NSString, not a UIFont.

    myScoreLabel.string = // as you had it (using the string property, not text)
    myScoreLabel.fontName = @"Arial";
    myScoreLabel.fontSize = 30.0;