设置UItextview的字体

时间:2011-12-11 06:49:17

标签: ios uiview fonts uitextview

我的uiview中有多个textview我需要设置此textviews的字体大小,所以我使用了以下代码,但它没有改变字体大小,

for (UIView *subview in self.view.subviews) {

    if ([subview isKindOfClass:[UITextView class]]) {

        ((UITextView *)subview).font = [UIFont fontWithName:@"Helvetica" size:12];
    }

}

1 个答案:

答案 0 :(得分:0)

正如@jrturton所说,也许你的文本视图是子视图的子视图,然后需要某种递归代码。例如:

-(void) setNewFontToTextViews:(UIView*) theView {
    if([[theView subviews] count]) 
        for( UIView * subView in [theView subviews])
            [self setNewFontToTextViews:subView] ;
    else if([theView isKindOfClass:[UITextView class]])
        [(UITextView*)theView setFont:[UIFont fontWithName:@"Helvetica" size:12]];
}