0

I have written a subclass for UIButton and I have this error

error: IB Designables: Failed to render and update auto layout status for ...: The agent crashed

. Could you please tell me what's wrong with my code? I'm using XCode 11.13.1 and Swift 5. And I have read this answer @IBDesignable crashing agent but it did not help me.

 import UIKit

@IBDesignable class MLButton: UIButton {

// MARK: - @IBInspectables
@IBInspectable var isActive: Bool = true {
    didSet {
        isUserInteractionEnabled = isActive
        configureUI()
    }
}

@IBInspectable var cornerRadius: CGFloat = 0 {
    didSet {
        layer.cornerRadius = cornerRadius
        clipsToBounds = true
    }
}

@IBInspectable var activeBackgroundColor: UIColor = Colors.newOrange {
    didSet {
        configureUI()
    }
}

@IBInspectable var inactiveBackgroundColor: UIColor = Colors.orangeBack {
    didSet {
        configureUI()
    }
}

@IBInspectable var activeTintColor: UIColor = UIColor.white {
    didSet {
        configureUI()
    }
}

@IBInspectable var inactiveTintColor: UIColor = Colors.newOrange {
    didSet {
        configureUI()
    }
}

// MARK: - Lifecycle
required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    commonInit()
}

override init(frame: CGRect) {
    super.init(frame: frame)
    commonInit()
}


// MARK: - Methods
private func commonInit() {
    titleLabel?.font = UIFont(.latoSemibold(size: 17))
}

private func configureUI() {
    tintColor = isActive ? activeTintColor : inactiveTintColor
    backgroundColor = isActive ? activeBackgroundColor : inactiveBackgroundColor
}
}

Using only from Storyboard. Storyboard code:

<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YTx-TM-kTh" customClass="MLButton" customModule="Preggie" customModuleProvider="target">
                                                <rect key="frame" x="0.0" y="0.0" width="240" height="50"/>
                                                <constraints>
                                                    <constraint firstAttribute="height" constant="50" id="f74-3Q-ay1"/>
                                                </constraints>
                                                <state key="normal" title="Создать аккаунт"/>
                                                <userDefinedRuntimeAttributes>
                                                    <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
                                                        <real key="value" value="7"/>
                                                    </userDefinedRuntimeAttribute>
                                                    <userDefinedRuntimeAttribute type="boolean" keyPath="isActive" value="YES"/>
                                                </userDefinedRuntimeAttributes>
                                                <connections>
                                                    <action selector="createAccountButtonDidTap" destination="y7n-q9-1CA" eventType="touchUpInside" id="nco-j7-YiR"/>
                                                </connections>
                                            </button>
  • Do you use this button as it is from storyboard or also set constraints/properties through swift programmatically? Can you post what you do on swift side with this button or what storyboard attributes you set for this? Actually looks functional locally in my machine with Xcode 11.3.1 (11C504) – denis_lor Mar 19 '20 at 08:21
  • @denis_lor Hi, I use it from storyboard only. I've posted code from storyboard in question. – Kyryl Nevedrov Mar 19 '20 at 08:43
  • That's great, so I mimic the same properties in my storyboard, also attached the button touchUpInside eventType and still working fine. Can you try cleaning xcode derived data, caching, closing it.. Looks like an issue with Xcode cached files, because as I said, mine is working fine. Same Xcode version.. – denis_lor Mar 19 '20 at 08:51

0 Answers0