skip to Main Content

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.

Img

2

Answers


  1. Your code works normally.
    I also have the same version [Xcode 12.5.1].

    enter image description here
    enter image description here

    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.

    import UIKit
    
    extension UIButton {
        
        func makeCircle() {
           self.layer.masksToBounds = true
           self.layer.cornerRadius = self.frame.width / 2
        }
     }
    

    result

    enter image description here

    Login or Signup to reply.
  2. 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.

    extension UIButton {
        
        func makeRounded(cornerRadius : CGFloat?) {
            
            if let cornerRadius_ = cornerRadius {
                self.layer.cornerRadius = cornerRadius_
            }  else {
                self.layer.cornerRadius = self.layer.frame.height / 2
            }
            
            self.layer.masksToBounds = true
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search