Skip to content

Commit

Permalink
Merge branch 'master' of github.com:touyu/SwiftyAttributedString
Browse files Browse the repository at this point in the history
  • Loading branch information
touyu committed May 15, 2017
2 parents 14dfaeb + 3ff453f commit 3048e13
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Create framework
$ carthage update --platform iOS
```

## Usage
## Example

```swift
textView.attributedText = "SwiftyAttributedString"
Expand All @@ -43,16 +43,37 @@ textView.attributedText = "SwiftyAttributedString"
range: .portion(of: .string("Attributed"))))
```

<img src="https://github.com/touyu/SwiftyAttributedString/blob/assets/001.png" height=70>

```swift
textView.attributedText = "sample text"
.add(attributes: [Attribute(value: .strikethroughStyle(1.0),
range: .portion(of: .string("sample"))),
Attribute(value: .underlineStyle(1.0),
range: .portion(of: .string("text")))])
textView.attributedText = "SwiftyAttributedString"
.add(attributes: [Attribute(value: .font(.systemFont(ofSize: 16))),
Attribute(value: .font(.boldSystemFont(ofSize: 16)),
range: .portion(of: .string("String"))),
Attribute(value: .foregroundColor(.blue),
range: .portion(of: .string("Swifty"))),
Attribute(value: .foregroundColor(.red),
range: .portion(of: .string("Attributed"))),
Attribute(value: .foregroundColor(.orange),
range: .portion(of: .string("String"))),
Attribute(value: .underlineStyle(1.0),
range: .portion(of: .string("Attributed")))])
```

<img src="https://github.com/touyu/SwiftyAttributedString/blob/assets/002.png" height=80>

<img src="https://github.com/touyu/SwiftyAttributedString/blob/assets/001.png" height=70>

## References
| Dictionary Key | Attributed Value |
| ----------------------------------------------| --------------------------------------------------- |
| `NSFontAttributeName` | `.font(UIFont)` |
| `NSForegroundColorAttributeName` | `.foregroundColor(UIColor)` |
| `NSBackgroundColorAttributeName` | `.backgroundColor(UIColor)` |
| `NSKernAttributeName` | `.kern(NSNumber)` |
| `NSStrikethroughStyleAttributeName` | `.strikethroughStyle(NSNumber)` |
| `NSUnderlineStyleAttributeName` | `.underlineStyle(NSNumber)` |
| `NSStrokeColorAttributeName` | `.strokeColor(UIColor)` |
| `NSStrokeWidthAttributeName` | `.strokeWidth(NSNumber)` |
| `NSShadowAttributeName` | `.shadow(NSShadow)` |
| `NSTextEffectAttributeName` | `.textEffect(SwiftyAttributedString.TextEffect)` |
| `NSLinkAttributeName` | `.link(URL)` |
| `NSBaselineOffsetAttributeName` | `.baselineOffset(NSNumber)` |
| `NSObliquenessAttributeName` | `.obliqueness(NSNumber)` |
| `NSExpansionAttributeName` | `.expansion(NSNumber)` |

0 comments on commit 3048e13

Please sign in to comment.