Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Pod/Classes/AKAttributeKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ open class AKAttributeKit {
3. **Insert UIColor:** Directly insert UIColor into swift string like `<tag \(myColor)>` 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 `<font \(myFont.asAKAttribute())>`
2. **System font:** Provide only fontSize to use system font
3. **Insert UIFont:** Directly insert UIFont into swift string like `<font \(myFont.asAKAttribute())>`
- ### Link
String of any valid URL format
*/
Expand Down Expand Up @@ -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)) {
Expand All @@ -309,4 +313,3 @@ extension AKAttributeKit {
return nil;
}
}

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `<a http://google.com>Google</a>`
`base` | NSBaselineOffsetAttributeName | `square<base 15>2</base>`
`bg` | NSBackgroundColorAttributeName | `<bg #00ff00>Green</bg>` or <code>\<bg 255&#124;255&#124;0>Yellow\</bg></code>
`ex` | NSExpansionAttributeName | `<ex 5>WIDE</ex>`
`fg` | NSForegroundColorAttributeName | `<fg #ff0000>Red</fg>` or <code>\<fg 0&#124;0&#124;255>Blue\</fg></code>
`font` | NSFontAttributeName | <code>Different \<font Arial&#124;18>Font\</font></code>
`font` | NSFontAttributeName | <code>Different \<font Arial&#124;18>Font\</font> and \<font 21>system font\</font></code>
`i` | NSObliquenessAttributeName | `<i 0.5>Italic</i>` or `<i 0.8>oblique</i>`
`k` | NSKernAttributeName | `<k 20>Huge Space</k>`
`sc`,<br/> `sw` | NSStrokeColorAttributeName,<br/> NSStrokeWidthAttributeName | `<sc #f00><sw 2>Storked Text</sw></sc>`
Expand All @@ -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 <br/> 2. **Integer sequence:** <code>r&#124;g&#124;b&#124;a</code> param sequence where all params in sequence are Int ranges from 0-255. <br/> 3. **Insert UIColor:** Directly insert UIColor into swift string like `<tag \(myColor)>` where myColor is any UIColor other than `colorWithPatternImage`. | `bg`, `fg`, `sc`, `tc`, `uc`
Font | 1. **Param sequence:** <code>fontName&#124;fontSize</code> param sequence where fontName is String and fontSize is Float <br/> 2. **Insert UIFont:** Directly insert UIFont into swift string like `<font \(myFont.asAKAttribute())>` | `font`
Font | 1. **Param sequence:** <code>fontName&#124;fontSize</code> param sequence where fontName is String and fontSize is Float <br/> 2. **System font:** Provide only fontSize to use system font <br/> 3. **Insert UIFont:** Directly insert UIFont into swift string like `<font \(myFont.asAKAttribute())>` | `font`

## Installation

Expand All @@ -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
Expand Down