CATextLayer 的文字被截断

我想在 UIView 中显示 CATextLayer 并更改 textlayer 的文本和字体。但是 textlayer 中的文本切断了右侧的设备。

最奇怪的是,如果我在后台发送应用程序然后再次打开它,问题就消失了!!

我的代码:

  import UIKit

class FontDetailViewController: UIViewController {

@IBOutlet weak var textField: UITextView!
@IBOutlet weak var layerTextView: UIView!

var font: Font!
let textLayer = CATextLayer()

override func viewDidLoad() {
    super.viewDidLoad()
    let titleFor = font.fontName.capitalized
    title = titleFor.replacingOccurrences(of: #"\b-"#,with: "",options: .regularExpression,range: nil)
    textLayer.frame = layerTextView.bounds


    setUpView(for: font)
    layerTextView.layer.masksToBounds = true
    layerTextView.layer.addSublayer(textLayer)
    
}

override func viewdidlayoutsubviews() {
    super.viewdidlayoutsubviews()
    textLayer.frame = layerTextView.bounds
    
}


func setUpView(for font: Font) {
    textField.font =  font.getUIFont()
    setUpTextLayer(font.getcTFont())

    
}

func setUpTextLayer(_ font: CTFont) {
    
    textLayer.frame = layerTextView.bounds
    let string = "Lorem ipsum dolor sit er elit lamet,consectetaur cillium adipisicing pecu,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."
    
    textLayer.string = string
    textLayer.font = font
    textLayer.fontSize = 14
    textLayer.foregroundColor = UIColor.darkGray.cgColor
    textLayer.isWrapped = true
    textLayer.alignmentMode = .center
    textLayer.truncationmode = .middle
    textLayer.contentsScale = UIScreen.main.scale
    
}
}

但是文本在 CTFont 中像这样在右侧被截断

CATextLayer 的文字被截断

但是如果我在后台发送应用程序并再次打开它,那么问题就这样消失了,

CATextLayer 的文字被截断

有谁能帮帮我吗? :(

daiandy001 回答:CATextLayer 的文字被截断

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1150418.html

大家都在问