码迷,mamicode.com
首页 > 移动开发 > 详细

iOS文字描边

时间:2016-05-19 20:53:39      阅读:571      评论:0      收藏:0      [点我收藏+]

标签:

当label用系统的字体干干巴巴的放在那会很难看,有时候我们需要给文字描边,让文字变得更漂亮

想用文字想要有描边的话就让你的label继承自CTWBLabe可以了,而且文字颜色和描边颜色可以自定义.

废话不多,直接上代码:

//

//  CTWBLabel.m

//  SpeedPro

//

//  Created by WBapple on 16/5/17.

//  Copyright © 2016年 Huawei. All rights reserved.

//

 

#import "CTWBLabel.h"

 

@implementation CTWBLabel

/**

 *  重写父类text方法

 *

 *  @param rect 文字描边

 */

- (void)drawTextInRect:(CGRect)rect

{

    //描边

    CGContextRef c = UIGraphicsGetCurrentContext ();

    CGContextSetLineWidth (c, 10);

    CGContextSetLineJoin (c, kCGLineJoinRound);

    CGContextSetTextDrawingMode (c, kCGTextStroke);

    //描边颜色

    self.textColor = [UIColor colorWithHexString:@"#29a5e5"];

    [super drawTextInRect:rect];

    //文字颜色

    self.textColor = [UIColor colorWithHexString:@"#ffb901"];

    CGContextSetTextDrawingMode (c, kCGTextFill);

    [super drawTextInRect:rect];

}

@end

 

iOS文字描边

标签:

原文地址:http://www.cnblogs.com/wangbinios/p/5509862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!