Text 仅使用1个UILabel子类创建笔划和阴影效果
我正在尝试创建一个UILabel子类,该子类将完成我使用以下方法堆叠的两个独立UILabel的任务: 背景标签:Text 仅使用1个UILabel子类创建笔划和阴影效果,text,uilabel,subclass,Text,Uilabel,Subclass,我正在尝试创建一个UILabel子类,该子类将完成我使用以下方法堆叠的两个独立UILabel的任务: 背景标签: - (void)drawTextInRect:(CGRect)rect { CGSize shadowOffset = self.shadowOffset; //UIColor *textColor = self.textColor; CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(c,
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
//UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 3);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
self.alpha = .1;
self.shadowOffset = shadowOffset;
}
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 2);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor blackColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.alpha = .5;
self.shadowOffset = shadowOffset;
}
前景标签:
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
//UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 3);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
self.alpha = .1;
self.shadowOffset = shadowOffset;
}
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 2);
CGContextSetTextDrawingMode(c, kCGTextStroke);
self.textColor = [UIColor blackColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
self.shadowOffset = CGSizeMake(0, 0);
[super drawTextInRect:rect];
self.alpha = .5;
self.shadowOffset = shadowOffset;
}
有没有办法只使用1个UILabel子类来完成这2组影响?试试下面的代码:
UILabel* label = [[UILabel alloc] init];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(0,1);