I have add the class RoundButton in Swift with the following code:
//
// RoundButton.swift
//
import UIKit
@IBDesignable
class RoundButton: UIButton {
@IBInspectable var roundButton : Bool = false {
didSet {
if roundButton == true {
layer.cornerRadius = frame.height / 2
}
}
}
override func prepareForInterfaceBuilder() {
if roundButton == true {
layer.cornerRadius = frame.height / 2
}
}
}
Then I have activate the design in the button properties. In the main.storyboard the buttons are square, but in the build the buttons are round. And it comes this error:
file:///Users/anonymoushuman/Documents/Apps/Taschenrechner/Taschenrechner/Base.lproj/Main.storyboard: error: IB Designables: Failed to render and update auto layout status for ViewController (BYZ-38-t0r): The bundle “Taschenrechner.app” couldn’t be loaded because its executable couldn’t be located.
2
Answers
Your code works normally.
I also have the same version [Xcode 12.5.1].
I searched for the errors you experienced, and I think it would be good to refer to the links.
I don’t know what caused the error, but let me suggest another way.
This code can also achieve the same results you want to achieve.
result
This is the extension I wrote. If you want to make a circle, not an ellipse, you can write
button.makeRounded(nil)
. The caution here is that when you make a circle, the vertical and horizontal heights must be equal and the values must be specified.