热门搜索 :
考研考公
您的当前位置:首页正文

ios开发 label描边

来源:东饰资讯网

代码如下:

新建outlineLabel

.h文件

#import@interface outLineLabel : UILabel

/** 描多粗的边*/

@property (nonatomic, assign) NSInteger outLineWidth;

/** 外轮颜色*/

@property (nonatomic, strong) UIColor *outLinetextColor;

/** 里面字体默认颜色*/

@property (nonatomic, strong) UIColor *labelTextColor;

@end

-----------------分割线---------

.m文件

#import "outLineLabel.h"

@implementation outLineLabel

- (void)drawTextInRect:(CGRect)rect {

CGContextRef c = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(c, self.outLineWidth);

CGContextSetLineJoin(c, kCGLineJoinRound);

CGContextSetTextDrawingMode(c, kCGTextStroke);

self.textColor = self.outLinetextColor;

[super drawTextInRect:rect];

self.textColor = self.labelTextColor;

CGContextSetTextDrawingMode(c, kCGTextFill);

[super drawTextInRect:rect];

}

@end

----------------分割线---------

应用

outLineLabel *label = [[outLineLabel alloc]init];

label.x = 0;

label.y = 73;

label.width = SCREEN_WIDTH;

label.height = 50;

[self.view addSubview:label];

label.text = [NSString stringWithFormat:@"x%zd",self.giftNum];

label.outLineWidth = 5;

label.outLinetextColor = RGB(249, 152, 147);

label.labelTextColor = [UIColor whiteColor];

Top