迅速不要重绘CATextLayer

我正在使用button的扩展用于将我自己的方法实现到UIButton,并创建一个CATextLayer用于在按钮中再添加1个文本,但是在此我用不同的参数(文本)调用此方法,而先前的文本仍在新文本之后一遍又一遍。我需要重涂我的按钮而没有堆栈文本(带有新文本的调用方法,并且只会有新文本)

extension UIButton{

    func spordacceptButaction(c_one: UIColor,c_two: UIColor,corner: Int,w: Int,number: Int,gradientLayer:CAGradientLayer){

        var textLayer: CATextLayer!

        let startFontSize: CGFloat = 60

        let startPosition: CGPoint = CGPoint(x: 0,y: 0)


        // Do any additional setup after loading the view,typically from a nib.
        // let gradientLayer = CAGradientLayer()
        textLayer = CATextLayer()
        textLayer.alignmentMode = CATextLayerAlignmentMode.left
        textLayer.anchorPoint = CGPoint(x: 0,y: 0)
        textLayer.bounds.size = CGSize(width: 100,height: 100)
        textLayer.contentsScale = UIScreen.main.scale
        textLayer.font = UIFont.systemFont(ofSize: startFontSize,weight: UIFont.Weight.semibold)
        textLayer.fontSize = startFontSize
        //  textLayer.backgroundColor = #colorLiteral(red: 0.521568656,green: 0.1098039225,blue: 0.05098039284,alpha: 1)
        textLayer.isWrapped = true
        textLayer.position = startPosition
        textLayer.string = String(number)

enter image description here

charlestri 回答:迅速不要重绘CATextLayer

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

大家都在问