I created a row of buttons programatically. The orange colours show up fine on iphoneXR (device) that has iOS14 and stay orange between dark and light mode. But on an iphone 11 with iOS13 (device), the title colour shows up only as black or white depending on dark/light mode. Why is orange being overridden? What can I do to keep the title orange for all the devices?
I tried running on ios11 simulator and the orange titles showed up there.
I set the buttons up programatically using a custom view:
These are some of the ways I tried changing the color:
I tried running on ios11 simulator and the orange titles showed up there.
I set the buttons up programatically using a custom view:
Code Block let attributedText = [NSAttributedString.Key.font: UIFont(name: "Poppins-Regular", size: 15.0)!] button1.layer.borderColor = #colorLiteral(red: 0.8196078431, green: 0.3568627451, blue: 0.2235294118, alpha: 1) button1.layer.borderWidth = 1.0 button1.setTitleColor(.placeholderText, for: .normal) button1.backgroundColor = UIColor.white button1.layer.cornerRadius = 32 button1.clipsToBounds = true button1.setAttributedTitle(NSAttributedString(string: "PLACEHOLDER TEXT", attributes: attributedText), for: .normal) button1.translatesAutoresizingMaskIntoConstraints = false self.addSubview(button1) self.addConstraint(NSLayoutConstraint(item: button1, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 0, constant: 64)) self.addConstraint(NSLayoutConstraint(item: button1, attribute: NSLayoutConstraint.Attribute.leading, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.leading, multiplier: 1, constant: 45)) self.addConstraint(NSLayoutConstraint(item: self, attribute: NSLayoutConstraint.Attribute.trailing, relatedBy: NSLayoutConstraint.Relation.equal, toItem: button1, attribute: NSLayoutConstraint.Attribute.trailing, multiplier: 1, constant: 45)) self.addConstraint(NSLayoutConstraint(item: button1, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0)) self.addConstraint(NSLayoutConstraint(item: button1, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: reScanButton!, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 15))
These are some of the ways I tried changing the color:
Code Block button.setTitleColor(.systemOrange, for: .normal) button.setTitleColor(.placeholderText, for: .normal) //this led to a grey color on ios14 as expected but black on iOS13 button.setTitleColor(UIColor.orange, for: .normal) button.setTitleColor(UIColor.customAccent, for: .normal) extension UIColor { static var customAccent: UIColor { if #available(iOS 13, *) { return UIColor { (traitCollection: UITraitCollection) -> UIColor in if traitCollection.userInterfaceStyle == .dark { return UIColor(red: 0.8196078431, green: 0.3568627451, blue: 0.2235294118, alpha: 1.0) } else { return UIColor(red: 0.8196078431, green: 0.3568627451, blue: 0.2235294118, alpha: 1.0) } } } else { return UIColor(red: 0.8196078431, green: 0.3568627451, blue: 0.2235294118, alpha: 1.0) } }