uilabel有轮廓或中风 [英] uilabel with outline or stroke
本文介绍了uilabel有轮廓或中风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何为UILabel创建文本笔划?有什么办法吗?
I was wondering how can I create text stroke for UILabel ? is there any possible way ?
谢谢你,
#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
}
现在的问题是如何我可以在不同的viewcontrollers上使用带有IBOutlet标签的子类。是对的:
now the question is how can i use this subclass with a IBOutlet label on different viewcontrollers . is it right :
label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 190, 190)];
推荐答案
根据具体情况,某些人可能会有所帮助字体和字符,添加:
It may be helpful to some to add that depending on font and characters, adding:
CGContextSetLineJoin(c,kCGLineJoinRound);
可以防止过多的笔划应用于过于尖锐的角色。
can prevent artifacts from too large a stroke applied to too sharp a character.
这篇关于uilabel有轮廓或中风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文