Do you sometimes you want to change the title of a text-only UIButton
while it is on the screen and the text flashes? The easiest way to fix that is to use the .custom
button type instead of .system
.
Here's some playground code to illustrate this:
import UIKit
import PlaygroundSupport
let view = UIView()
view.backgroundColor = .green
view.frame = CGRect(x: 0, y: 0, width: 200, height: 300)
let b = UIButton(type: .system) //Switch to .custom
b.frame = CGRect(x: 10, y: 10, width: 70, height: 24)
b.setTitle("foo", for: .normal)
b.setTitleColor(.red, for: .normal)
view.addSubview(b)
PlaygroundPage.current.liveView = view
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
b.setTitle("bar", for: .normal)
}
.
.