简体   繁体   English

iOS UITextView类别设置字体

[英]IOS UITextView category set font

I created a category class which standardize the feel and look of UITextView. 我创建了一个类别类,用于标准化UITextView的外观。 I manage to add border with the code below but not sure how to set font name, font color. 我设法用下面的代码添加边框,但不确定如何设置字体名称,字体颜色。

#import "UITextView+Form.h"
#import <QuartzCore/QuartzCore.h>

@implementation UITextView (Form)

-(void)standardize{
    CALayer *thisLayer = self.layer;
    thisLayer.borderWidth=3.0;
    thisLayer.borderColor=[UIColor blackColor].CGColor;

}
@end

This method should work for you: 此方法应为您工作:

-(void)standardize{
    CALayer *thisLayer = self.layer;
    thisLayer.borderWidth=3.0;
    thisLayer.borderColor=[UIColor blackColor].CGColor;

    // Set whatever point size you want
    self.font = [UIFont systemFontOfSize:10.0f];    

    // Set whatever color you want
    self.textColor = [UIColor black];
}

These should help too. 这些也应该有所帮助。

UIFont class reference: UIFont类参考:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIFont_Class/Reference/Reference.html http://developer.apple.com/library/ios/#documentation/uikit/reference/UIFont_Class/Reference/Reference.html

UIColor class reference: UIColor类参考:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIColor_Class/Reference/Reference.html http://developer.apple.com/library/ios/#documentation/uikit/reference/UIColor_Class/Reference/Reference.html

Add these lines to your standardize method: 将这些行添加到您的standardize方法中:

self.textColor = [UIColor ...]; // whatever color you want
self.font = [UIFont ...]; // whatever font you want

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM