ios开发,关于图文混排

ios开发,关于图文混排,第1张

图文混排

CTFrameRef textFrame // coreText 的 frame

CTLineRef line // coreText 的 line

CTRunRef run // line 中的部分文字

相关方法:

CFArrayRef CTFrameGetLines(CTFrameRef frame ) //获取包含CTLineRef的数组

void CTFrameGetLineOrigins(

CTFrameRef frame,

CFRange range,

CGPoint origins[] ) //获取所有CTLineRef的原点

CFRange CTLineGetStringRange (CTLineRef line )//获取line中文字在整段文字中的Range

CFArrayRef CTLineGetGlyphRuns (CTLineRef line )//获取line中包含所有run的数组

CFRange CTRunGetStringRange (CTRunRef run ) //获取run在整段文字中的Range

CFIndex CTLineGetStringIndexForPosition(

CTLineRef line,

CGPoint position ) //获取点击处position文字在整段文字中的index

CGFloat CTLineGetOffsetForStringIndex(

CTLineRef line,

CFIndex charIndex,

CGFloat* secondaryOffset ) //获取整段文字中charIndex位置的字符相对line的原点的x值

主要步骤:

1)计算并存储文字中保含的所有表情文字及其Range

2)替换表情文字为指定宽度的NSAttributedString

CTRunDelegateCallbacks callbacks

callbacks.version = kCTRunDelegateVersion1

callbacks.getAscent = ascentCallback

callbacks.getDescent = descentCallback

callbacks.getWidth = widthCallback

callbacks.dealloc = deallocCallback

CTRunDelegateRef runDelegate = CTRunDelegateCreate(&callbacks, NULL)

NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:

(id)runDelegate, (NSString*)kCTRunDelegateAttributeName,

[UIColor clearColor].CGColor,(NSString*)kCTForegroundColorAttributeName,

nil]

NSAttributedString *faceAttributedString = [[NSAttributedString alloc] initWithString:@"*" attributes:attrDictionaryDelegate]

[weiBoText replaceCharactersInRange:faceRange withAttributedString:faceAttributedString]

[faceAttributedString release]

3) 根据保存的表情文字的Range计算表情图片的Frame

textFrame 通过CTFrameGetLines 获取所有line的数组 lineArray

遍历lineArray中的line通过CTLineGetGlyphRuns获取line中包含run的数组 runArray

遍历runArray中的run 通过CTRunGetStringRange获取run的Range

判断表情文字的location是否在run的Range

如果在 通过CTLineGetOffsetForStringIndex获取x的值 y的值为line原点的值

仅供参考

在通讯录里点击你自己 进去后右上角有个编辑啊就可以改了。

通讯录里建一个自己的名字和手机号码,然后在设置里面选择邮件、通讯录、日历,里面有个我的信息,选择自己新建的那个自己的名字

如果不想要显示出来,很简单,直接进通信录删除上面对应显示的人的信息即可!


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11475863.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存