-1

Button title and image not geting rendered. Works fine in iOS13 and below, but after updating to Xcode12.0.1 and iOS14, it is not working.

let viewAllButton: RoundedButton = {
   let button = RoundedButton()
    button.translatesAutoresizingMaskIntoConstraints = false
    button.backgroundColor = .red
    button.setTitle("View all", for: .normal)
    button.setTitleColor(.white, for: .normal)
    return button
}()

 class RoundedButton: UIButton {
     override func draw(_ rect: CGRect) {
       super.draw(rect)
       self.layer.cornerRadius = self.bounds.height / 2
       self.layer.masksToBounds = true
     }
}

Release Mode iOS 14 Debug Mode iOS 14

Kedar Sukerkar
  • 1,410
  • 1
  • 16
  • 22

2 Answers2

0

Try to set the title color before setting setTitle. (I had some issues with something like this too).

0

Xcode 12.0.1, iOS 14, Swift 5.3

Actually the problem was in the redundant code which was lying around in my codebase.

extension UIButton {
    open override func layoutSubviews() {
        super.layoutSubviews()
      }
  }

I just had this sitting in my extensions. This didnt cause any issues in iOS 13 and below.

Steps to reproduce:

  1. Add above code in your project.
  2. Run the project(Release or Debug Mode) the project in your simulator(Button renders properly) and Kill the app.
  3. Now, Launch the app by clicking App icon and you will see Button contents disappear.

Strange bug, i hope it save someones time.

Kedar Sukerkar
  • 1,410
  • 1
  • 16
  • 22