Reshad Reshad - 4 months ago 8
Swift Question

Swift UIButton not appearing on screen

I have a view in my tabbar controller where I would like to show a button. I create this button programmatically based of a condition, therefore I use the following code but nothing is appearing:

override func viewDidLoad() {
if !Settings.getIsConnected() {

func notConnected() {
let connectBtn = UIButton(frame: CGRect(x:, y:, width: 200, height: 45))
connectBtn.setTitle("Connect", forState: .Normal)
connectBtn.addTarget(self, action:#selector(self.pressedConnect(_:)), forControlEvents: .TouchUpInside)

print("Button created")

func pressedConnect(sender: UIButton!) {


I am clueless on what I am doing wrong. Anyone got suggestions? Cause it does print out "Button created" so it definitely runs the code inside the noConnected() method.


Adding a background color to your UIButton, and add a tint color to the title will resolve the problem