textview不增加动态字体大小



我试图有动态字体大小的textview。我已经为文本视图的动态字体大小创建了一个自定义类。我为自定义类使用了以下代码:

#import "CustomTextView.h"
@implementation CustomTextView

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

@end

,但这不起作用。它为textview显示了黑色。请指导一下怎么做?

在ViewController中实现"CustomTextView.h"时一定有问题。让我们知道你是怎样做的。在ViewController中共享你的代码。你是否在你的视图控制器中添加了"CustomTextView"作为子视图

最新更新