【问题标题】:Swift - @IBDesignable - Rotation not shown inside StoryboardSwift - @IBDesignable - 故事板内未显示旋转
【发布时间】:2016-12-16 21:34:27
【问题描述】:

为什么transform rotation 没有在情节提要中显示/预览?它在应用程序中运行良好。我的 @IBDesignable 类中还有其他可以正常工作的属性。

我怎样才能做到这一点?

@IBDesignable
class CustomUILabel: UILabel {

    @IBInspectable var label_Rotation: Double = 0 {
        didSet {

            rotateLabel(label_Rotation)

        }
    }

    func rotateLabel(labelRotation: Double)  {
        self.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2 + labelRotation))
    }

}

【问题讨论】:

    标签: ios swift uilabel transform ibdesignable


    【解决方案1】:

    这似乎适用于以下结果(可能是您所期望的):

    注意:我在 Swift 4 中有这个

    @IBDesignable
    class CustomUILabel: UILabel {
    
        @IBInspectable var label_Rotation: Double = 0 {
            didSet {
                rotateLabel(labelRotation: label_Rotation)
                self.layoutIfNeeded()
            }
        }
    
        func rotateLabel(labelRotation: Double)  {
            self.transform = CGAffineTransform(rotationAngle: CGFloat((Double.pi * 2) + labelRotation))
        }
    }
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-08
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多