I have a xcode playground. When I press the Assistant Editor button, I see my view with the buttons and labels. I had also setup an action for the button. But I cannot click it there. Please help.
The Code:
import UIKit
import PlaygroundSupport
import XCPlayground
class Responder: NSObject {
@objc func respond() {
print("Hello World")
}
}
var responder = Responder()
var view: UIView = {
let sampleView = UIView(frame: CGRect(x: 00, y: 00, width: 200, height: 500))
sampleView.backgroundColor = UIColor.white
return sampleView
}()
var button: UIButton = {
let sampleButton = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
sampleButton.backgroundColor = UIColor.white
sampleButton.setTitle("Click Here", for: .normal)
sampleButton.setTitleColor(UIColor.black, for: .normal)
sampleButton.addTarget(responder, action: #selector(Responder.respond), for: .touchUpInside)
return sampleButton
}()
var label: UILabel = {
let sampleLabel = UILabel(frame: CGRect(x: 40, y: 40, width: 150, height: 20))
sampleLabel.backgroundColor = UIColor.white
sampleLabel.adjustsFontSizeToFitWidth = true
sampleLabel.text = "Hello World. I am a label"
sampleLabel.textColor = UIColor.black
return sampleLabel
}()
func setupLayout() {
view.addSubview(button)
view.addSubview(label)
PlaygroundPage.current.liveView = view
}
setupLayout()
A screenshot: