This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension ViewController: UICollectionViewDelegate { | |
| func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
| print("selected item at \(indexPath)") | |
| } | |
| } | |
| extension ViewController: UICollectionViewDataSource { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { | |
| var foods = ["🍎", "🍌", "🍓"] | |
| func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
| print("selected item at \(indexPath)") | |
| } | |
| func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
| return foods.count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @IBOutlet weak var myCustomView: UIView! { | |
| didSet { | |
| view.backgroundColor = UIColor.blue | |
| view.layer.cornerRadius = myCustomView.bounds.width / 2 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lazy var myCustomView: UIView = { | |
| let view = UIView() | |
| view.backgroundColor = UIColor.blue | |
| view.layer.cornerRadius = myCustomView.bounds.width / 2 | |
| return view | |
| }() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myCustomView = UIView() | |
| override func viewDidLoad() { | |
| myCustomView.backgroundColor = UIColor.blue | |
| myCustomView.layer.cornerRadius = myCustomView.bounds.width / 2 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyButton: UIButton { | |
| var action: (() -> ())? | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| sharedInit() | |
| } | |
| required init?(coder aDecoder: NSCoder) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewDidLoad() { | |
| let button = MyButton() | |
| button.action = { | |
| print("MyButton pressed!") | |
| } | |
| view.addSubview(button) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewDidLoad() | |
| let button = UIButton() | |
| button.addTarget(self, action: #selector(uiButtonAction), for: .touchUpInside) | |
| view.addSubview(button) | |
| } | |
| @objc private func uiButtonAction() { | |
| print("UIButton pressed!") | |
| } |