TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to SWIFT

Swift UIFont Example: Name and Size

UIFont. Times New Roman, Helvetica, San Francisco, Comic Sans: these are fonts. For a professional program design, a good font is essential.
But fonts can convey meaning. For example Times New Roman looks serious. Comic Sans looks childlike. In Swift we apply the UIFont class to change fonts dynamically.
To begin, please add a Text Field to your iPhone program. Then add an outlet to it in your ViewController.swift file. Control click and drag it.UITextField

Next: We want to change the font property of our UITextField. We create a UIFont with a name and size argument.

UIFont: Some init methods for UIFont return an optional UIFont. So we can make sure they are valid with an if-let statement.

Optionals: if let
Example UIFont, font property: Swift // // ViewController.swift // ExampleTime7 // // ... // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Create UIFont with Times New Roman. // ... Set size to 19.0. let font = UIFont(name: "Times New Roman", size: 19.0) // Use font on UITextField. simpleText.font = font } @IBOutlet weak var simpleText: UITextField! override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
Run simulator. When we run the simulator, we see the result of our work. We must type some text into the Text Field. The text should have a serif font.
A review. With methods on the UIFont class we look up font objects. But we can also create new UIFont instances with the init method.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf