【问题标题】:iOS - UILabel with custom font and dynamic sizeiOS - 具有自定义字体和动态大小的 UILabel
【发布时间】:2013-06-10 20:22:42
【问题描述】:

我正在尝试在我的 iOS 应用程序中创建一个使用自定义字体的 UILabel。为此,我从 UILabel 扩展了一个类,实现如下所示:

@implementation CustomFontLabel

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setFont:[UIFont fontWithName:@"Museo" size:12.0]];
    }
    return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setFont:[UIFont fontWithName:@"Museo" size:12.0]];
    }
    return self;    
}

-(void)setFontSize:(int)size {
    [self setFont:[UIFont fontWithName:@"Museo" size:size]];
}

@end

当我使用 XIB 时,我将标签的类设置为“CustomFontLabel”。我将字体大小设置为 26。 问题是,当我在代码中将字体大小设置为“12”时,它没有选择 26。

有人能指出我在哪里做错了没有将字体大小设为“26”吗?

【问题讨论】:

  • 谢谢@borrrden 你应该把它作为答案,我会接受它。

标签: ios uilabel font-size


【解决方案1】:

字体大小将作为initWithCoder: 方法的一部分设置,因此您应该只使用self.font.pointSize 而不是12.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多