Skip to content

Instantly share code, notes, and snippets.

@esbenp
Created August 20, 2017 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esbenp/28bc12ecaa7522bfde8babf45e592585 to your computer and use it in GitHub Desktop.
Save esbenp/28bc12ecaa7522bfde8babf45e592585 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
public class ProductTable : UIView {
open var quantity : NSNumber = 0 {
didSet {
updateLabel()
}
}
var Label: UILabel!
var Button: UIButton!
override init(frame: CGRect){
super.init(frame: frame)
Label = UILabel(frame: CGRect(x: 0, y: 0, width: 400,
height: 50))
Button = UIButton(frame: CGRect(x: 0, y: 55, width: 400, height: 50))
Button.backgroundColor = UIColor.blue
Button.setTitle("Increase quantity on the Swift side", for: .normal)
Button.setTitleColor(UIColor.white, for: .normal)
Button.addTarget(self, action: #selector(ProductTable.onClick), for: .touchUpInside)
updateLabel()
self.addSubview(Label)
self.addSubview(Button)
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public func updateLabel() {
let number = String(quantity as! Int)
Label.text = "On the Swift side, quantity is now: " + number
}
func onClick() {
NSLog("onClick")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment