iOS 镂空文字效果
来源:互联网 发布:装修花费知乎 编辑:程序博客网 时间:2024/06/10 06:20
注意:一定要继承于UILabel,如果继承于UIView的话镂空的效果出不来
#import <UIKit/UIKit.h>
@interface HollowOutLabel : UILabel
@end
#import "HollowOutLabel.h"
@implementation HollowOutLabel
{
NSString * _text;
UIFont * _font;
UIColor * _backgroundColor;
CGRect _frame;
}
#pragma mark - 重写对应的set方法
- (void)setText:(NSString *)text
{
_text = text;
}
- (void)setFont:(UIFont *)font
{
_font = font;
}
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
_backgroundColor = backgroundColor;
}
//这个方法会出问题,因而重写置空
- (void)sizeToFit
{
}
- (instancetype)init//禁止使用此方法初始化
{
returnnil;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [superinitWithFrame:frame]) {
_frame = frame;
}
returnself;
}
#pragma mark - 绘制
- (void)drawRect:(CGRect)rect
{
CGContextRef context =UIGraphicsGetCurrentContext();
[selfdrawSubtractedText:_textinRect:_frameinContext:context];
}
- (void)drawSubtractedText:(NSString *)text inRect:(CGRect)rect inContext:(CGContextRef)context
{
//将当前图形状态推入堆栈
CGContextSaveGState(context);
//设置混合色
CGContextSetBlendMode(context,kCGBlendModeDestinationOut);
//label上面添加label
UILabel *label = [[UILabelalloc] initWithFrame:rect];
label.font =_font;
label.text = text;
label.textAlignment =NSTextAlignmentCenter;
label.backgroundColor =_backgroundColor;
[label.layerdrawInContext:context];
//把堆栈顶部的状态弹出,返回到之前的图形状态
CGContextRestoreGState(context);
}
@end
- iOS 镂空文字效果
- 时尚的3D镂空文字效果实例教程
- Photoshop文字之——打造压纹镂空文字效果
- iOS UILabel镂空特效
- iOS 渐变文字效果
- iOS实现View镂空效果
- 在ios中实现图片环绕文字效果
- IOS UILabel 的使用及文字效果
- iOS 特种label:镂空文字、类歌词进度显示文字
- iOS 特种label:镂空文字、类歌词进度显示文字
- iOS中间透明周围不透明(镂空)方法实现特种ProgressBar
- 字体镂空
- OpenGL镂空
- 镂空三角形
- 镂空圆
- 镂空点击
- 镂空菱形
- 金属文字效果
- 深度探索QT窗口系统---几何篇2
- 奇异值分解(SVD)原理详解及推导
- Java多线程-生产者与消费者
- 微信小程序tabBar使用
- web前端页面性能优化小结
- iOS 镂空文字效果
- Dojo1.11官方教程文档翻译(4.5)使用声明式语法
- iOS让键盘消失,取消第一响应,取消一级响应
- crontab语法高亮
- Linux系统下连接Oracle数据库,创建新的数据库用户及分配权限
- MongoDB学习笔记—Linux下搭建MongoDB环境
- 用Maven部署war包到远程Tomcat服务器
- Android动画-帧动画-属性动画
- [isayme]Xshell配色方案