uilabel有轮廓或中风

Mom*_*omi 6 iphone uilabel ios4

我想知道如何为UILabel创建文本笔划?有什么办法吗? 在此输入图像描述

谢谢 ,

#import <Foundation/Foundation.h>


@interface CustomLabel : UILabel {

 }

 @end

#import "CustomLabel.h"


@implementation CustomLabel

- (void)drawTextInRect:(CGRect)rect {

    CGSize shadowOffset = self.shadowOffset;
    UIColor *textColor = self.textColor;

    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(c, 22);

    CGContextSetTextDrawingMode(c, kCGTextStroke);
    self.textColor = [UIColor whiteColor];
    [super drawTextInRect:rect];

    CGContextSetTextDrawingMode(c, kCGTextFill);
    self.textColor = textColor;
    self.shadowOffset = CGSizeMake(0, 0);
    [super drawTextInRect:rect];

    self.shadowOffset = shadowOffset;
    //works fine with no warning 
}   
Run Code Online (Sandbox Code Playgroud)

现在的问题是我如何在不同的viewcontrollers上使用带有IBOutlet标签的子类.这样对吗 :

    label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 190, 190)];
Run Code Online (Sandbox Code Playgroud)

小智 3

根据字体和字符添加这一点可能会对某些人有所帮助,添加:

CGContextSetLineJoin(c,kCGLineJoinRound);
Run Code Online (Sandbox Code Playgroud)

可以防止因对过于锐利的字符应用过大的笔画而产生的伪影。