动态UITextView字体大小

时间:2013-03-12 17:06:46

标签: objective-c uitextview

我有一个UITextView来展示一些文字,textView是用代码创建的:

UITextView *textView = [[UITextView alloc] initWithFrame:labelFrame];
[textView setFont:[UIFont systemFontOfSize:prefObj.Setting_Font_Size]];
textView = NO;
textView = NSTextAlignmentJustified;
textView = [UIColor clearColor];
textView = UIViewAutoresizingFlexibleHeight;
[self addSubview:textView];

prefObj.Setting_Font_Size默认值为16 ,,用户可以更改设置面板中的字体,,,一旦用户选择了我希望反映到UITextView的新尺寸, ,我用它来更新字体大小:

-(void)updateFontSize
{
    [textView setFont:[UIFont systemFontOfSize:prefObj.Setting_Font_Size]];
}

我确信prefObj.Setting_Font_Size的值会保留新选择的尺寸,但是文字保持不变,但我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

解决方案很简单,但我忘了UITextView是在UIView类中创建的,

所以我将UITextView的实例作为UIView类中的属性,并更改我创建UIView的字体大小:

UIView子类:

@interface TextToShow : UIView

@property (nonatomic, strong) UITextView *textView;

@end
UIViewController中的

TextToShow *TextToShowView = [[TextToShow alloc] initWithFrame:Frame];

[TextToShowView.textView setFont:[UIFont systemFontOfSize:prefObj.Setting_Font_Size]];