@IBInspectable not updating Story Board

≡放荡痞女 提交于 2019-12-11 12:23:01

问题


My custom button below works fine on the iOS Simulator - when I set a rotation in Interface Builder it rotates the button when I run the app.

However, I can't see the rotation in the Story Board - it just shows the button without applying the transformation.

It doesn't matter if I do the transformation inside the drawRect method - same result.

import Foundation
import UIKit


@IBDesignable class CustomButton: UIButton {

    @IBInspectable var rotation: CGFloat = 0.0 {
        didSet {
            self.transform = CGAffineTransformMakeRotation(CGFloat(rotation))
        }
    }

    override func drawRect(rect: CGRect) {
        // ...
    }
}

回答1:


I think it is safe to say "It is @IBDesignable Bug in Xcode 7.1.1"

Because:

  1. Running project does show the CGAffineTransform with the given rotation.
  2. If borderWidth, borderColor etc. are changed in this didSet block, it shows in the Storyboard correctly.
  3. I could not find anything in the apple developer site that says transformation will not work for @IBDesignable


来源:https://stackoverflow.com/questions/33545455/ibinspectable-not-updating-story-board

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!