@IBDesignable error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed

前端 未结 22 2154
终归单人心
终归单人心 2020-12-02 04:45

I have a very simple subclass of UITextView that adds the "Placeholder" functionality that you can find native to the Text Field object. Here is my code for the su

22条回答
  •  遥遥无期
    2020-12-02 04:55

    Make sure that you are not directly initialising UIImage or UIFont using assets or fonts added in your project.

    I always create a private func setUp() in my @IBDesignable custom UI classes. which is called from init(frame: CGRect), init?(coder aDecoder: NSCoder). So I finally updated the setup() as the following.

    private func setUp() {
    
         //... Doing initial configurations
    
         // iconImageView.image = UIImage(named: "IconImageName")! // Causing the Crash, use if let OR guard let instead
         if let icon = UIImage(named: "IconImageName") {
              iconImageView.image = icon
              iconImageView.frame.size = icon.size
         }
    
         // nameLabel.font =  UIFont(name: "Calibri-Light", size: 15.0) // Causing the Crash, use if let OR guard let instead
         if let font = UIFont(name: "Calibri-Light", size: size) {
              nameLabel.font =  font
         } else {
              nameLabel.font = UIFont.systemFont(ofSize: size) 
         }
    
         // Doing other stuffs
    }
    

提交回复
热议问题