0

I'm messing around in a Swift playground, trying to demonstrate different types of UIButtons built into the Cocoa library. And I'm curious why this works:

Creating a button that works

and yet this doesn't:

enter image description here

The only thing I'm doing differently should be constructing them. The first one, I'm constructing using UIButton's constructor; the second one, I'm creating using a UIButton static method that returns anyObject that should be a button of the given type. So, in effect, they should be the same, right? Why does the first one display for me, yet the second one doesn't?

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53

1 Answers1

0

You can see that button into Assistant Editor like this:

First add import XCPlayground at the top of your playGround then add this code:

var myButton1 = UIButton.buttonWithType(.Custom) as! UIButton
myButton1.frame = CGRectMake(0, 0, 300, 100)
myButton1.backgroundColor = UIColor.redColor()
myButton1.setTitle("This is a button", forState: .Normal)
XCPShowView("View Title",myButton1)

To show the assistant editor goto View > Assistant Editor > Show Assistant Editor

And you can see your button like this:

enter image description here

Hope this will help.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
  • This does fix my problem, thanks! However, I'm still kind of confused as to why it won't show in the quick view as above - is it being interpreted differently by the system? – Green Cloak Guy Jul 22 '15 at 06:59
  • I think compiler is taking this differently. thats why it is not showing you like other button code. – Dharmesh Kheni Jul 22 '15 at 07:01