meitu / mpitextkit Goto Github PK
View Code? Open in Web Editor NEWPowerful text framework for iOS to display rich text based on TextKit, inspired by Texture and YYText.
License: MIT License
Powerful text framework for iOS to display rich text based on TextKit, inspired by Texture and YYText.
License: MIT License
我在使用MPITextKit中发现一个小问题。
将普通字符串解析为包含View的富文本字符串是比较耗时的,应在子线程解析。
但是如果MPITextAttachment的content是view或layer,又面临子线程操作View的问题。
因此是否可以让MPITextAttachment支持View的懒加载。
实现思路大致如下:
/// 定义一个MPITextAttachmentContent协议用来懒加载View
@objc protocol MPITextAttachmentContent: NSObjectProtocol {
@objc var view: UIView? { get }
@objc func removeView()
}
/// 示例
class CSTextAttachmentContent: NSObject, MPITextAttachmentContent {
// CSTextComponent是一个枚举类型,可以用来生成不同类型的View
let component: CSTextComponent
private(set) lazy var view: UIView? = {
return component.attachmentView
}()
init(component: CSTextComponent) {
self.component = component
}
func removeView() {
view?.removeFromSuperview()
}
}
/// 重写MPITextAttachment
- (void)drawAttachmentInRect:(CGRect)rect textView:(UIView *)textView {
UIView *view = nil;
CALayer *layer = nil;
UIImage *image = nil;
if ([self.content isKindOfClass:[UIView class]]) {
view = self.content;
} else if ([self.content conformsToProtocol:@protocol(MPITextAttachmentContent)]){
id<MPITextAttachmentContent> c = self.content;
view = c.view;
} else if ([self.content isKindOfClass:[CALayer class]]) {
layer = self.content;
} else if ([self.content isKindOfClass:UIImage.class]) {
image = self.content;
}
if (image) {
[image drawInRect:rect];
} else if (view) {
if (!CGRectEqualToRect(view.frame, rect)) {
view.frame = rect;
}
if (view.superview != textView) {
[textView addSubview:view];
}
}else if (layer){
if (!CGRectEqualToRect(layer.frame, rect)) {
layer.frame = rect;
}
if (layer.superlayer != textView.layer) {
[textView.layer addSublayer:layer];
}
}
}
如题
用demo 中MPITextSelectionViewController 修改成frame布局 ,选择文字时手势响应范围变小。基本都在绿色线条标记的地方才可以响应拖动。kGrabberTouchHitTestExtend kKnobTouchHitTestExtend这两个值设置很大也没有用。请问怎么样才能增大触控拖动的响应范围,这样会使操作看起来更灵敏一点。
textView.backgroundColor = [UIColor lightGrayColor];
textView.textContainerInset = UIEdgeInsetsMake(30, 30, 30, 30);
textView.frame = CGRectMake(30, 100, self.view.frame.size.width-60, 100)
如上图,左侧那个标签应该显示在右侧红线位置,但是目前显示异常了, 当点击右侧的昵称(是一个MPITextLink)时,会恢复正常显示。
PS:设置标签和链接的部分代码如下:
//标签
let attachment = MPITextAttachment()
attachment.content = liveAnchorView //这里是个UIView
attachment.verticalAligment = .center
attachment.contentSize = liveAnchorView.anchorSize
attachment.contentMode = .scaleAspectFit
let tempAttr = NSMutableAttributedString(attachment: attachment)
//链接
attributedString.mpi_setAttribute(NSAttributedString.Key.MPILink.rawValue, value: MPITextLink(value: selectorStr as NSObjectProtocol), range: rangeVal)
attributedString.mpi_setAttribute(NSAttributedString.Key.foregroundColor.rawValue, value: rangeColor as Any, range: rangeVal)
另外,为了让Label支持显示为RTL方式,需要给paragraphStyle
设置属性baseWritingDirection
的值为.rightToLeft
:
let isRTL = UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.baseWritingDirection = isRTL ? .rightToLeft : .leftToRight
paragraphStyle.alignment = .natural
finalAttr.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: finalAttr.length))
在给出的Example MPITextKit Demo中测试点击Text Attachment,可以明显看到内存泄露导致的内存增长。
YYText 的 Text Attriutes Demo当中,我长按一个标签或者link,并不会像MPITextKit 那样子,直接就触发点击事件,而是当点击才会真正触发,不知道 MPITextKit 能否修改下。
异步渲染时,attributedText为nil,不能复制。
RT
目前文字颜色不会跟着系统样式变化
当文本是纯表情Unicode或者含有表情Unicode,进行选择复制,会导致复制失败,应该是选择的范围不正确。
MPITextKit_Example[1129:283853] Could not save pasteboard named com.apple.UIKit.pboard.general. Error: Error Domain=PBErrorDomain Code=2 "Cannot represent object of class __NSCFString as representation of type public.utf8-plain-text" UserInfo={NSLocalizedDescription=Cannot represent object of class __NSCFString as representation of type public.utf8-plain-text}
测试文本:😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸😸
还请作者能修复下
021-06-19 16:51:01.422476+0800 [Unknown process name] CGBitmapContextInfoCreate: unable to allocate 57747456 bytes for bitmap data
2021-06-19 16:51:01.422619+0800 [Unknown process name] CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.422670+0800 [Unknown process name] CGContextSetShouldAntialias: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.422724+0800 [Unknown process name] CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.422783+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.422861+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.422911+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423582+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423642+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423684+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423776+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423816+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423856+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.423964+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.424569+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.424634+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.424680+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.424725+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.424925+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.424968+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.425479+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.425526+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.425582+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426236+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426290+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426332+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426693+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426794+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426848+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.426889+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.427308+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.427396+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.427590+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.427665+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.427705+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.427746+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.428337+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.428394+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.428524+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.428577+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.429346+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.429433+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.429476+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.429540+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.429606+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430009+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430481+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430524+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430564+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430646+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430721+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.430804+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.431287+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.431398+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.431439+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.431481+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.431607+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.431643+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432470+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432526+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432563+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432628+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432711+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432745+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.432778+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.433294+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.433334+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.433391+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.433434+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.433467+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.433652+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434171+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434216+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434249+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434281+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434816+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434858+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434897+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434930+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.434983+0800 [Unknown process name] CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.435615+0800 [Unknown process name] CGContextSetTextMatrix: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436023+0800 [Unknown process name] CGContextSetFont: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436060+0800 [Unknown process name] CGContextSetFontSize: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436093+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436218+0800 [Unknown process name] CGContextSetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436337+0800 [Unknown process name] CGContextGetTextDrawingMode: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436388+0800 [Unknown process name] CGContextGetFontRenderingStyle: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2021-06-19 16:51:01.436800+0800 [Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
如何重现
1、info.plist只勾选Portrait
2、AppDeleagte里实现
3、MPITextSelectionViewController实现
4、进入MPITextSelectionViewController后长按文字出现『菜单』然后选择区域,主要是「保证MPITextEffectWindow单例被创建」
5、横竖屏切换即可复现
可复现的Demo,全局搜索语句"MPITextKit/issues" 查看改动的地方
MPITextKit_issue.zip
解决方案
在Demo中,「MPITextEffectWindow.m的37行」,使用MPITextEffectWindowViewController代替UIViewController
iOS 13系统以下, 内容过长时,异步渲染,渲染不出来!高度5500以上就渲染不出来
如题
1.长按滑动选择过程中,触控不灵敏,触控过小。如何可以扩大范围。
2.选择滑动过程中。没有选择范围变化的监听回调。是否考虑加上。
还望大佬给予指点
请问能否支持textview显示包含有MPITextAttachment的富文本?
我直接用例子里的 我的阿勒泰...
那段文本 label
设置 label.textAlignment = NSTextAlignmentCenter;
发现文本并没有居中对齐。只有设置了 [one mpi_setAlignment:NSTextAlignmentCenter range:one.mpi_rangeOfAll];
才居中对齐起作用。
目前项目中使用Swift语言开发,在实现MPILabel 的协议方法- (void)labelWillBeginSelection:(MPILabel *)label selectedRange:(NSRangePointer)selectedRange ,不能设置selectedRange,在Swift中无法对方法中的参数进行修改,请求解决方案
一般文本可以选择是长按文本触发的,现在遇到一个,假设第一次长按选择了全部的文本。然后触摸空白选择文本取消。这时候在文本上轻扫(比如:右下角往左上角扫动)就可以再触发选择而不是通过长按触发。麻烦作者看下
[self.nameMPILabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(contentView).offset(12);
make.left.equalTo(contentView);
make.right.equalTo(contentView).offset(-12);
}];
{
NSMutableAttributedString *text = [NSMutableAttributedString new];
UIFont *font = [UIFont systemFontOfSize:14];
image = [UIImage imageWithCGImage:image.CGImage scale:2 orientation:UIImageOrientationUp];
MPITextAttachment *attach = [MPITextAttachment new];
attach.content = image;
NSMutableAttributedString *attachText = [[NSAttributedString attributedStringWithAttachment:attach] mutableCopy];
[text appendAttributedString:attachText];
[text appendAttributedString:[[NSAttributedString alloc] initWithString:@" " attributes:nil]];
NSString *title = @"fffffffffffffffffff";
[text appendAttributedString:[[NSAttributedString alloc] initWithString:title attributes:nil]];
[text addAttribute:NSFontAttributeName value:font range:text.mpi_rangeOfAll];
self.nameMPILabel.attributedText = text;
}
您好,我们文本有双击处理其他事件的功能,这时候如果双击的是文本超链接内容 会和我们双击出发的事件有冲突,会导致两个都执行。那我有什么办法把超链接的双击事件获取到,或者屏蔽掉么。
UIScrollView里面添加MPILabel ,MPILabel编辑状态,长按选择后拖动选择框,有没有回调,让外层的UIScrollView也跟着滚动?
e.g. attributedString like "aaa [fun][fun][fun] aaaaa"
i will replace [fun] to a image, with MPITextAttachment, using replaceCharacters function.
when the string like this "[a][b]" replace fine, but the string like "[a][a]" i won't get two image, i just a one twice width's image
but i change the MPITextAttachment to NSTextAttachment, just work fine.
通过 [label sizeThatFits:CGSizeMake(textMaxWidth, MAXFLOAT)]; 方法计算文本的所需要的高度,如果富文本中没有换行操作,是正常的,如果有换行操作,计算的size大小会偏高。我同时设置了行高样式
NSMutableParagraphStyle *paragraphStyle =[[NSMutableParagraphStyle alloc] init];
[paragraphStyle setParagraphStyle:[NSMutableParagraphStyle defaultParagraphStyle]];
paragraphStyle.lineHeightMultiple = 1.2;
[attributedString addAttributes:@{NSParagraphStyleAttributeName:paragraphStyle} range:NSMakeRange(0,attributedString.length)];
1、问题:selectable = true时,在文本「MPITextLinkAttributeName」的范围外,文本内点击,则不会有任何响应,导致无法触发其他点击事件。另外,点击除MPILabel外的地方,selectable的选中范围也不会消失。
2、场景:例如,我在UICollectionViewCell上加了MPILabel,给文本中的一小段文字加了「MPITextLinkAttributeName」实现富文本点击效果,如果我点击文本的其他区域就无法触发UICollectionView的didSelectItemAtIndexPath
代理。
3、期望:开启selectable的情况下,但是未出现选择区域时,点击时MPILabel需要响应其他的点击事件。另外,点击除MPILabel外的地方也应该让选择区域消失
4、可复现的Demo:
「MPITextTruncatingViewController」里有注释的代码可以测试
MPITextKit-master.zip
autolayout跟attributedText,计算出来的宽度是偏小的,导致文字被break成了。。。
发现给MPILabel设置textAlignment后,再给attributedText赋值,textAlignment是不会被用到,需要手动调一下
- (void)mpi_setAlignment:(NSTextAlignment)alignment range:(NSRange)range;
请问这里是基于什么考虑呢?
objc[245]: Class _NSZombie__MPILinkedMapNode is implemented in both ?? (0x1c5644170) and ?? (0x1c56441a0). One of the two will be used. Which one is undefined.
没有看到有地方使用MPITextParser
的代码
OC:
NSMutableAttributedString *attributedText = [NSMutableAttributedString new];
NSAttributedString *linkAttributedText = [[NSAttributedString alloc] initWithString:@"Tap Me dsdsdsldslkdlskdlsd"];
[attributedText appendAttributedString:linkAttributedText];
MPITextBackground *background = [MPITextBackground backgroundWithFillColor:[UIColor grayColor] cornerRadius:5];
[attributedText addAttribute:MPITextBackgroundAttributeName value:background range:NSMakeRange(0, 8)];
MPILabel *label = [MPILabel new];
label.highlightedLinkTextAttributes = nil;
label.delegate = self;
label.numberOfLines = 0;
label.attributedText = attributedText;
label.frame = CGRectMake(0, 200, 300, 100);
[self.view addSubview:label];
Swift
let helloWorldAttributedText = NSMutableAttributedString.init(string: "Tap Me dsdsdsldslkdlskdlsd")
let attributedText = NSMutableAttributedString.init()
attributedText.append(helloWorldAttributedText)
let background = MPITextBackground(fill: .gray, cornerRadius: 5)
attributedText.addAttribute(NSAttributedString.Key.MPIBlockBackground, value: background, range: .init(location: 0, length: 5))
let mpiLabel = MPILabel.init()
mpiLabel.highlightedLinkTextAttributes = nil
mpiLabel.numberOfLines = 0
mpiLabel.delegate = self
mpiLabel.attributedText = attributedText
mpiLabel.frame = .init(x: 0, y: 200, width: 300, height: 100)
self.view.addSubview(mpiLabel)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.