动态字体大小不起作用?

Dynamic font size is not working?

我想为 app.For 中的标签和文本视图提供动态字体大小,我为此做了一些自定义 classes。

对于标签

#import "CustomLabel.h"

@implementation CustomLabel


- (void)drawRect:(CGRect)rect
{
    // Drawing code
    self.font = [UIFont fontWithName:self.font.fontName size:((self.frame.size.height / self.numberOfLines) - 4)];
}


@end

我已经为标签添加了这个 class 但是当我 运行 应用程序时它没有显示任何 label.Please 告诉我哪里错了?

您需要从您的 drawRect 调用 UILabel。

-(void)drawRect:(CGRect)rect {
    // Drawing code
    self.font = [UIFont fontWithName:self.font.fontName size:((self.frame.size.height / self.numberOfLines) - 4)];

    [super drawRect: rect];
}