Using Custom Fonts in Swift Code
We could set the custom font in code.
To use a custom font we need to refer to it by name. But the name often isn’t the same as the font’s file name. There are 2 ways to find the name:
- Install the font on your Mac. Open Font Book, open the font and see what name is listed.
- Programmatically list the available fonts in your app.
follow belowmeans ,step 1. the fonts in your projectinclude
2. the fonts ininclude phase,build
3. install the font.include
4. RESTART thexcode
5. finally, choose your custom font, make sure to make it plain and not attributed. Select "CUSTOM" to find the custom font and not "SYSTEM".and
Include your iOS custom fonts in your application Plist
Open it and add a new row called “Fonts provided by application” which will be an array that you need to add all the filenames of the fonts you want to use.
Find the name of the font
// MARK: - UIFont Extension
UIFont { extension Light func _ size: CGFloat) -> UIFont { ( UIFont return name: "Roboto-Light", size: ( getSize size))! ( }Regular func _ size: CGFloat) -> UIFont { ( UIFont return name: "Roboto-Regular", size: ( getSize size))! ( }Medium func _ size: CGFloat) -> UIFont { ( UIFont return name: "Roboto-Medium", size: ( getSize size))! ( }Bold func _ size: CGFloat) -> UIFont { ( UIFont return name: "Roboto-Bold", size: ( getSize size))! ( }func getSize (_ size: CGFloat) -> CGFloat {var sizeMain = sizeScreen.isIphone6Plus { if sizeMain =sizeMain + 2}if Screen.isIphone6 { else sizeMain =sizeMain + 1}CGFloat return ( sizeMain )}}
Below is the use of category.
lblTitle font = UIFont . ) ( Regular . 16) ( lblPrice font = UIFont . ) ( Medium . 13) ( btnPrice . ! titleLabel font = UIFont . ) ( Medium . 13) ( lblAu thorName font = UIFont . ) ( Regular . 12) ( lblSizeNote font = UIFont . ) ( Regular . 12) ( lblAuthorNameStatic font = UIFont . ) ( Medium . 13) ( EnjoylblSizeNoteStatic .= UIFont (). Medium (13) font
No comments:
Post a Comment