问题描述
我必须从 txt 创建阅读器视图。我必须按字符串数组拆分 txt 并将其显示在屏幕上。我知道屏幕可以容纳的字符数,但我必须记住固体字。我的意思是如果每页的字符数 = 256 但单词从 255 开始并在 260 结束,我必须将此单词添加到数组的新元素中。请问你能帮帮我吗? 这里计算字符的方法:
func numberOfCharactersThatFitTextView() -> Int {
let fontRef = CTFontCreateWithName(R.font.poppinsBold.fontName as CFString,fontSize,nil)
let attributes = [kCTFontAttributeName : fontRef]
let attributedString = NSAttributedString(string: text,attributes: attributes as [NSAttributedString.Key : Any])
let frameSetterRef = CTFramesetterCreateWithAttributedString(attributedString as CFAttributedString)
var characterFitRange: CFRange = CFRange()
CTFramesetterSuggestFrameSizeWithConstraints(frameSetterRef,CFRangeMake(0,0),nil,CGSize(width: bounds.size.width,height: bounds.size.height),&characterFitRange)
return Int(characterFitRange.length)
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)