美文网首页
ios 文字外描边实现

ios 文字外描边实现

作者: yycache | 来源:发表于2020-03-16 17:54 被阅读0次

自定义UIlabel来实现。

在.h文件中添加属性

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/// 标准文字外描边

@interface MGPGLabel : UILabel

/// 外描边颜色

@property (strong,nonatomic) UIColor *strokeColor;

/// 外描边宽度

@property (assign,nonatomic) CGFloat strokeWidth;

@end

NS_ASSUME_NONNULL_END

然后在.m文件中 重写drawTextInRect 方法

#import "MGPGLabel.h"

@implementation MGPGLabel

- (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

相关文章

  • ios 文字外描边实现

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

  • ios 文字外描边效果

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

  • AE实现内描边和外描边

    AE并没有直接提供内描边和外描边选项,不过可以通过“位移路径”实现。 点击“图层”下方“内容”的“添加”按钮。 选...

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

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

  • ios开发文字内描边效果

    实现了外描边效果之后,产品问内描边好做吗,我说简单!简单个蛋! 因为苹果本身的描边效果,是双向描边,不是单侧的,见...

  • Android TextView字体描边

    原文:链接地址 今天公司要求做一个字体描边功能,在网上搜到一个不错的,可以实现改变文字描边宽度和描边颜色,功能实现...

  • 文字描边

  • 文字描边

    效果: 描边完成了,喜欢就留个小❤️吧

  • 使用CSS给文字添加描边效果

    CSS如何实现文字描边效果?下面本篇文章就来给大家介绍一下使用CSS给文字添加描边效果的方法,希望对大家有所帮助。...

  • ios lable字体描边+外发光

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

网友评论

      本文标题:ios 文字外描边实现

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