From ce083dcbf2c5f8ad808bb4da387d3da83715614d Mon Sep 17 00:00:00 2001 From: Vitaliy Ribachenko Date: Thu, 13 Apr 2017 15:47:12 +0300 Subject: [PATCH] Add possibility to use system font --- Pod/Classes/AKAttributeKit.swift | 9 ++++++--- README.md | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/AKAttributeKit.swift b/Pod/Classes/AKAttributeKit.swift index 49d6843..9cc2e75 100644 --- a/Pod/Classes/AKAttributeKit.swift +++ b/Pod/Classes/AKAttributeKit.swift @@ -71,7 +71,8 @@ open class AKAttributeKit { 3. **Insert UIColor:** Directly insert UIColor into swift string like `` where myColor is any UIColor other than `colorWithPatternImage`. - ### Font 1. **Param sequence:** `fontName|fontSize` param sequence where fontName is String and fontSize is Float - 2. **Insert UIFont:** Directly insert UIFont into swift string like `` + 2. **System font:** Provide only fontSize to use system font + 3. **Insert UIFont:** Directly insert UIFont into swift string like `` - ### Link String of any valid URL format */ @@ -299,7 +300,10 @@ extension AKAttributeKit { fileprivate class func fontFromString(_ fontStr:String)->UIFont? { var components = fontStr.components(separatedBy: "|"); - if components.count >= 2 { + if components.count == 1 { + let fontSize = components[0].toFailSafeInt() + return UIFont.systemFont(ofSize: CGFloat(fontSize)) + } else if components.count >= 2 { let fontName = components[0].trim() let fontSize = components[1].toFailSafeInt() if let font = UIFont(name: fontName, size: CGFloat(fontSize)) { @@ -309,4 +313,3 @@ extension AKAttributeKit { return nil; } } - diff --git a/README.md b/README.md index ad936cb..e46ea1e 100644 --- a/README.md +++ b/README.md @@ -43,14 +43,14 @@ There are some other libraries to create NSAttributedString form HTML. This is n ## Tags (Short Reference) -Tag | Attribute | Example +Tag | Attribute | Example --- | --- | --- `a` | NSLinkAttributeName | `Google` `base` | NSBaselineOffsetAttributeName | `square2` `bg` | NSBackgroundColorAttributeName | `Green` or \Yellow\ `ex` | NSExpansionAttributeName | `WIDE` `fg` | NSForegroundColorAttributeName | `Red` or \Blue\ - `font` | NSFontAttributeName | Different \Font\ + `font` | NSFontAttributeName | Different \Font\ and \system font\ `i` | NSObliquenessAttributeName | `Italic` or `oblique` `k` | NSKernAttributeName | `Huge Space` `sc`,
`sw` | NSStrokeColorAttributeName,
NSStrokeWidthAttributeName | `Storked Text` @@ -69,7 +69,7 @@ Link | Any valid URL format | `a` Int | Any integer value supported by respective attribute | `t`, `u` Float | Any float value | `base`, `ex`, `i`, `k`, `sw` Color | 1. **Hex formats:** `rgb`, `rgba`, `rrggbb`, `rrggbbaa` with or without `0x` or `#` prefix
2. **Integer sequence:** r|g|b|a param sequence where all params in sequence are Int ranges from 0-255.
3. **Insert UIColor:** Directly insert UIColor into swift string like `` where myColor is any UIColor other than `colorWithPatternImage`. | `bg`, `fg`, `sc`, `tc`, `uc` -Font | 1. **Param sequence:** fontName|fontSize param sequence where fontName is String and fontSize is Float
2. **Insert UIFont:** Directly insert UIFont into swift string like `` | `font` +Font | 1. **Param sequence:** fontName|fontSize param sequence where fontName is String and fontSize is Float
2. **System font:** Provide only fontSize to use system font
3. **Insert UIFont:** Directly insert UIFont into swift string like `` | `font` ## Installation @@ -84,7 +84,7 @@ pod "AKAttributeKit" Below is some TODOs that I have plan to implement. New ideas and/or help on current tasks are most welcome :D -- [ ] For common tags with (almost) obvius choices make parameter optional. +- [ ] For common tags with (almost) obvious choices make parameter optional. - [x] underline - [x] italic - [x] Strike through