简体   繁体   中英

IOS UITextView category set font

I created a category class which standardize the feel and look of 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:

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

UIColor class reference:

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

Add these lines to your standardize method:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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