美文网首页
ios lable字体描边+外发光

ios lable字体描边+外发光

作者: guoguojianshu | 来源:发表于2021-07-26 11:10 被阅读0次

继承label的一个类,实现

@interface custom : UILabel
@property (strong,nonatomic) UIColor *strokeColor;
@property (assign,nonatomic) CGFloat strokeWidth;
@end
@implementation custom

- (void)drawTextInRect:(CGRect)rect
{
    if (self.strokeWidth > 0) {
        CGSize shadowOffset = self.shadowOffset;
        UIColor *textColor = self.textColor;

        CGContextRef c = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(c, self.strokeWidth);
        CGContextSetLineJoin(c, kCGLineJoinRound);
        //画外边
        CGContextSetTextDrawingMode(c, kCGTextStroke);
        self.textColor = self.strokeColor;
        [super drawTextInRect:rect];
        //画内文字
        CGContextSetTextDrawingMode(c, kCGTextFill);
        self.textColor = textColor;
        self.shadowOffset = CGSizeMake(0, 0);
        [super drawTextInRect:rect];
        self.shadowOffset = shadowOffset;
    } else {
        [super drawTextInRect:rect];
    }
}
@end

使用方法

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    custom * label = [custom new];
    label.frame = CGRectMake(160, 70, 150, 100);
    label.text = @"Hello";
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor greenColor];
    label.font = [UIFont systemFontOfSize:30];
    //描边
    label.strokeColor = [UIColor orangeColor];
    label.strokeWidth = 1;
    //发光
    label.layer.shadowRadius = 10;
    label.layer.shadowColor = [UIColor colorWithRed:230/255.0 green:75/255.0 blue:248/255.0 alpha:1.0].CGColor;
    label.layer.shadowOffset = CGSizeMake(0, 0);
    label.layer.shadowOpacity = 1.0;
    [self.view addSubview:label];
    
}

相关文章

  • ios lable字体描边+外发光

    继承label的一个类,实现 使用方法

  • 字体描边

    (void)drawTextInRect:(CGRect)rect {CGSize shadowOffset = ...

  • 【iOS UI篇】Label描边+发光字

    本文介绍如何给Label实现酷炫的描边+外发光效果,虽然实现简单,但是网上资料却是很少。 绘制实现描边 继承Lab...

  • ios 文字外描边效果

    设计提出文字描边效果,但是富文本自带的文字描边效果,是向文字内外同时描边 效果 所以需要自己实现,采用的方法是重写...

  • ios 文字外描边实现

    自定义UIlabel来实现。 在.h文件中添加属性 #import NS_ASSUME_NONNULL_BEGIN...

  • Shader第二十五讲:描边及外发光(转)

    描边以及外发光一般有如下几种实现方法: 【一贴图加工】 原理: 直接在贴图上对应模型边缘的位置画描边,凹的地方画阴...

  • NGUI字体描边

    NGUI的UILabel中实现字体的描边是通过以方形的方式对字体网格顶点偏移一定位置后作为其描边网格。以这种方式描...

  • CSS制作渐变描边等文字特效

    前端开发工作中遇到的文本有很多特效,比如渐变色、描边、带渐变色的描边、文字外发光、投影等等。现在总结一些经验,方便...

  • iOSUILable边距设置

    在iOS中Lable是没有UIEdgeInsets这个属性可以调用的,那么我们想修改下Lable的上下左右的边距该...

  • canvas

    绘制文字 strokeText(text,x,y)描边文字 font='size 字体' 设置字体大小和字体,如:...

网友评论

      本文标题:ios lable字体描边+外发光

      本文链接:https://www.haomeiwen.com/subject/qwgwmltx.html