YHDrawImage
轻量级,文本加自定义边框背景转换成图片,常用于富文本特殊字符加圆角边框背景
示例
安装
CocoaPods (推荐)
打开 Podfile 并编辑:
pod 'YHDrawImage', :git => 'https://github.com/yelinux/YHDrawImage.git'
执行命令 pod install or pod update.
手动
把 YHDrawImage/Classes 文件夹拖进你的项目.
使用
- 在使用的地方或pch文件里加入头文件:
#import "YHDrawImage.h"
- 创建实例YHDrawModel并设置文本边框属性,并执行draw方法获得图片:
UIImage *img1 = YHDrawModel.new
.string(@"V", @{NSForegroundColorAttributeName:UIColor.whiteColor, NSFontAttributeName:[UIFont boldSystemFontOfSize:10]})//文本+属性
.fill(color)//背景颜色
.radius(2, UIRectCornerAllCorners)//圆角
.size(CGSizeMake(15, 15))//固定宽高
.draw;
UIImage *img = YHDrawModel.new
.attributes(attr)//文本
.fill(UIColor.whiteColor)//背景颜色
.stroke(color, 1)//边框颜色,边框宽度
.radius(2, UIRectCornerAllCorners)//圆角
.padding(0, 6, 0, 4)//内边距
.size(CGSizeMake(0, 15))//固定宽高,0表示不固定,随内容自适应
.margin(0, 1, 0, 1)//外边距
.draw;//绘制
源码
作者
WeChat:chenyehong666888, E-mail:ichenevan@126.com
License
YHDrawImage is available under the MIT license. See the LICENSE file for more info.