博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
苹果爸爸Bug之NSTextAttachment
阅读量:7090 次
发布时间:2019-06-28

本文共 2214 字,大约阅读时间需要 7 分钟。

NSTextAttachment 自定义后的循环引用问题

  • NSTextAttachment的封装类
#import "DDAutoFitTextAttachment.h"@implementation DDAutoFitTextAttachment/** 重载此方法 使得图片的大小和行高是一样的。 @param textContainer textContainer @param lineFrag lineFrag @param position position @param charIndex charIndex @return attachmentBounds */- (CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex{    return CGRectMake(0, -3, lineFrag.size.height, lineFrag.size.height);}@end复制代码
  • NSAttributedString的分类
#import "NSAttributedString+DDLabel.h"#import "DDAutoFitTextAttachment.h"@implementation NSAttributedString (DDLabel)- (instancetype)initWithTitle:(NSString *)title                    titleFont:(UIFont *)titleFont                   titleColor:(UIColor *)titleColor                        image:(UIImage *)image                imagePosition:(DDAttributedStringImagePosition)imagePosition{        NSMutableAttributedString *superAttrStr = [[NSMutableAttributedString alloc]                                        initWithString:title                                        attributes:                                        @{
NSFontAttributeName: titleFont, NSForegroundColorAttributeName: titleColor}]; DDAutoFitTextAttachment *imageAttachment = [[DDAutoFitTextAttachment alloc] init]; imageAttachment.image = image; NSAttributedString *imageAttStr = [NSAttributedString attributedStringWithAttachment:imageAttachment]; switch (imagePosition) { case DDAttributedStringImagePositionLeft: { [superAttrStr insertAttributedString:imageAttStr atIndex:0]; } break; case DDAttributedStringImagePositionMiddle: { NSAssert(imagePosition != DDAttributedStringImagePositionMiddle , @"图片不能设置为 DDAttributedStringImagePositionMiddle"); } break; case DDAttributedStringImagePositionRight: { [superAttrStr insertAttributedString:imageAttStr atIndex: superAttrStr.length]; } break; } return superAttrStr.copy;}复制代码

只有这么几行代码,只是为了调整图片与文字的大小.

  • 结果 竟然没有释放

转载地址:http://vsiql.baihongyu.com/

你可能感兴趣的文章
Android Studio怎样删除module
查看>>
selective search生成.mat文件
查看>>
POJ2823 Sliding Window【双端队列】
查看>>
ssh-remote-port-forwarding
查看>>
System V IPC(1)-消息队列
查看>>
51单片机GPIO口模拟串口通信
查看>>
信息、数据与数据结构
查看>>
Webpack 2 视频教程 020 - Webpack 2 中的 HMR ( Hot Module Replacement )
查看>>
Android 高亮指示层提示
查看>>
Spark MLlib中的OneHot哑变量实践
查看>>
淘宝npm镜像使用方法
查看>>
Tomcat禁用SSLv3和RC4算法
查看>>
面向对象葵花宝典阅读思维导图(一)
查看>>
Tomcat Server.xml详解
查看>>
CSS媒体查询(@media)
查看>>
Linux(Ubuntu)下MySQL的安装与配置
查看>>
如何提取一个转录本的3'UTR区域的序列
查看>>
得到当前日期前一天的零时零分零秒及当前日的零时零分零秒
查看>>
内存堆与栈的区别
查看>>
NHibernate初学者指南(12):日志
查看>>