UIKit Framework - Snippets: Unterschied zwischen den Versionen
Aus Wikizone
| Zeile 12: | Zeile 12: | ||
label.text = "Hello" | label.text = "Hello" | ||
label.frame = CGRect(x: 0, y: 0, width: 100, height: 50) | label.frame = CGRect(x: 0, y: 0, width: 100, height: 50) | ||
| − | + | ||
| + | // add the label to the view. AddSubview needs a view as param. As UILabel inherits from UIView it's possible | ||
| + | view.addSubview(label) | ||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 4. Januar 2023, 09:01 Uhr
Base View
import UIKit
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red //Shortcut for UIColor.red
let label = UILabel()
label.text = "Hello"
label.frame = CGRect(x: 0, y: 0, width: 100, height: 50)
// add the label to the view. AddSubview needs a view as param. As UILabel inherits from UIView it's possible
view.addSubview(label)
}
}