【问题标题】:Trying to change the size of a font in my iPhone game and getting this error尝试在我的 iPhone 游戏中更改字体大小并收到此错误
【发布时间】:2015-02-03 02:58:26
【问题描述】:

我有以下内容,我试图以大字体获取此标签。我正在执行以下操作:

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

我收到此错误:Incompatible pointer types assigning NSString *'from UIFont *'

他们是改变字体大小的另一种方式吗?谢谢我对Objective C编码有点陌生,我正在尝试在构建一个小游戏的同时学习。提前致谢。

【问题讨论】:

    标签: ios iphone fonts cocos2d-iphone size


    【解决方案1】:

    UILabel 不提供stringfontName 属性。试试...

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

    EDIT - 现在明白这是一个 cocos2d 控件。我对它的经验有限,但看一下 CCTLabelTTF 的文档表明fontNameNSString,而不是UIFont

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

    【讨论】:

    • 感谢您的回复,不走运。我收到以下错误:在 CCTLabelTTF *' 类型的对象上找不到属性“文本”和在 CCTLabelTTF * 类型的对象上找不到属性“字体”
    • 哦...非常重要的是,这不是 UILabel,而是 cocos2d 的一部分。绝对更新您的问题和标签。我以对 cocos2d 的最佳理解进行了编辑。
    • 非常感谢!完美运行。对不起,我没有说清楚。
    猜你喜欢
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 2015-07-20
    • 1970-01-01
    • 2021-02-16
    • 2022-12-04
    相关资源
    最近更新 更多