Swift - View Extensions: Unterschied zwischen den Versionen
Aus Wikizone
(Die Seite wurde neu angelegt: „The Swifty way is to create an extension. An extension can be used to modify any property of UILabel. For example, if you have basic labels: An extension o…“) |
|||
| Zeile 1: | Zeile 1: | ||
| + | == Links == | ||
| + | [[Swift (Programmiersprache)]] | ||
| + | |||
| + | == Swift Extension == | ||
The Swifty way is to create an extension. | The Swifty way is to create an extension. | ||
Aktuelle Version vom 29. Dezember 2022, 22:23 Uhr
Links[Bearbeiten]
Swift (Programmiersprache)
Swift Extension[Bearbeiten]
The Swifty way is to create an extension.
An extension can be used to modify any property of UILabel.
For example, if you have basic labels:
An extension of UILabel could be created like this as an example:
extension UILabel {
func crazyShadow(color: UIColor = UIColor.red, size: CGSize = CGSize(width: 5, height: 5)) {
self.shadowColor = color
self.shadowOffset = size
}
}
//Then used like this
@IBOutlet var testLabel1: UILabel!
@IBOutlet var testLabel2: UILabel!
@IBOutlet var testLabel3: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
testLabel1.crazyShadow()
testLabel2.crazyShadow()
testLabel3.crazyShadow(color: UIColor.cyan)
}