Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a UIButton to Swift Playground?

So I opened up playground, I just want to add a simple UIButton (or a simple UIView) for testing purposes. I can't get it to display though. This is what I have so far:

import UIKit

var uiButton    = UIButton.buttonWithType(UIButtonType.System) as UIButton
uiButton.frame  = CGRectMake(0, 0, 100, 100)
uiButton.setTitle("Test", forState: UIControlState.Normal);
//self.view.addSubview(uiButton) <-- doesn't work

Do you guys know what I'm doing wrong? Thanks

like image 500
Shai UI Avatar asked Oct 18 '25 05:10

Shai UI


1 Answers

I think you can add button into playground and your code is correct you can see your button here when you click on Quick Look:

enter image description here

or you can see that button with clicking on Value History:

enter image description here

you dont need to add that into view.

like image 79
Dharmesh Kheni Avatar answered Oct 22 '25 07:10

Dharmesh Kheni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!