Skip to content

Commit

Permalink
updates to Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
wess committed Dec 21, 2016
1 parent 5d88550 commit ec56370
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 191 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# Veneer
> A simple library for building attributed strings, for a more civilized age.

_A simple library for building attributed strings, for a more civilized age._

---

Veneer was created to make creating attributed strings easier to read and write. Taking inspiration from SnapKit, Veneer uses blocks to construct the attributes and produce an NSAttributedString.

---


### Installation:
```ruby
pod "Veneer"
```


### Usage:
---
```swift
let attrString = NSAttributedString(string: "Hello World") { make in
make.font(UIFont.boldSystemFontOfSize(32.0))
make.backgroundColor(.red
make.color(.white)
}

someLabel.attributedText = attrString

```

### Author:
Wess Cope
- me@wess.io
- [@wesscope](https://twitter.com/wesscope)
122 changes: 61 additions & 61 deletions Veneer/Sources/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,91 @@ import Foundation
import UIKit

public enum TextEffectStyle {
case LetterPress
case letterPress

public var attributeName:String {
switch self {
case .LetterPress:
case .letterPress:
return NSTextEffectLetterpressStyle
}
}
}

public enum TextDirection : Int {
case Horizontal = 0
case Vertical = 1
case horizontal = 0
case vertical = 1
}

public enum StringAttribute {
case Font(UIFont)
case ParagraphStyle(NSParagraphStyle)
case Color(UIColor)
case BackgroundColor(UIColor)
case Ligature(Bool)
case Kerning(CGFloat)
case Strikethrough(NSUnderlineStyle)
case UnderlineStyle(NSUnderlineStyle)
case UnderlineColor(UIColor)
case StrikethroughColor(UIColor)
case StrokeColor(UIColor)
case StrokeWidth(CGFloat)
case Shadow(NSShadow)
case TextEffect(TextEffectStyle)
case Attachment(NSTextAttachment)
case Link(NSURL)
case LinkString(String)
case BaseLineOffset(CGFloat)
case Obliqueness(CGFloat)
case Expansion(CGFloat)
case WritingDirection([NSWritingDirectionFormatType])
case Direction(TextDirection)
case font(UIFont)
case paragraphStyle(NSParagraphStyle)
case color(UIColor)
case backgroundColor(UIColor)
case ligature(Bool)
case kerning(CGFloat)
case strikethrough(NSUnderlineStyle)
case underlineStyle(NSUnderlineStyle)
case underlineColor(UIColor)
case strikethroughColor(UIColor)
case strokeColor(UIColor)
case strokeWidth(CGFloat)
case shadow(NSShadow)
case textEffect(TextEffectStyle)
case attachment(NSTextAttachment)
case link(URL)
case linkString(String)
case baseLineOffset(CGFloat)
case obliqueness(CGFloat)
case expansion(CGFloat)
case writingDirection([NSWritingDirectionFormatType])
case direction(TextDirection)

public var map:(String, AnyObject) {
switch self {
case .Font(let font):
case .font(let font):
return (NSFontAttributeName, font)
case .ParagraphStyle(let style):
case .paragraphStyle(let style):
return (NSParagraphStyleAttributeName, style)
case .Color(let color):
case .color(let color):
return (NSForegroundColorAttributeName, color)
case .BackgroundColor(let color):
case .backgroundColor(let color):
return (NSBackgroundColorAttributeName, color)
case .Ligature(let ligature):
return (NSLigatureAttributeName, Int(ligature))
case .Kerning(let kerning):
return (NSKernAttributeName, kerning)
case .Strikethrough(let strikethrough):
return (NSStrikethroughStyleAttributeName, strikethrough.rawValue)
case .UnderlineStyle(let underline):
return (NSUnderlineStyleAttributeName, underline.rawValue)
case .StrokeColor(let color):
case .ligature(let ligature):
return (NSLigatureAttributeName, ligature as! AnyObject)
case .kerning(let kerning):
return (NSKernAttributeName, kerning as AnyObject)
case .strikethrough(let strikethrough):
return (NSStrikethroughStyleAttributeName, strikethrough.rawValue as AnyObject)
case .underlineStyle(let underline):
return (NSUnderlineStyleAttributeName, underline.rawValue as AnyObject)
case .strokeColor(let color):
return (NSStrokeColorAttributeName, color)
case .StrokeWidth(let width):
return (NSStrokeWidthAttributeName, width)
case .Shadow(let shadow):
case .strokeWidth(let width):
return (NSStrokeWidthAttributeName, width as AnyObject)
case .shadow(let shadow):
return (NSShadowAttributeName, shadow)
case .TextEffect(let effect):
return (NSTextEffectAttributeName, effect.attributeName)
case .Attachment(let attachment):
case .textEffect(let effect):
return (NSTextEffectAttributeName, effect.attributeName as AnyObject)
case .attachment(let attachment):
return (NSAttachmentAttributeName, attachment)
case .Link(let link):
return (NSLinkAttributeName, link)
case .LinkString(let link):
return (NSLinkAttributeName, link)
case .BaseLineOffset(let offset):
return (NSBaselineOffsetAttributeName, offset)
case .UnderlineColor(let color):
case .link(let link):
return (NSLinkAttributeName, link as AnyObject)
case .linkString(let link):
return (NSLinkAttributeName, link as AnyObject)
case .baseLineOffset(let offset):
return (NSBaselineOffsetAttributeName, offset as AnyObject)
case .underlineColor(let color):
return (NSUnderlineColorAttributeName, color)
case .StrikethroughColor(let color):
case .strikethroughColor(let color):
return (NSStrikethroughColorAttributeName, color)
case .Obliqueness(let obliqueness):
return (NSObliquenessAttributeName, obliqueness)
case .Expansion(let expansion):
return (NSExpansionAttributeName, expansion)
case .WritingDirection(let directions):
return (NSWritingDirectionAttributeName, directions.map{ $0.rawValue })
case .Direction(let direction):
return (NSVerticalGlyphFormAttributeName, direction.rawValue)
case .obliqueness(let obliqueness):
return (NSObliquenessAttributeName, obliqueness as AnyObject)
case .expansion(let expansion):
return (NSExpansionAttributeName, expansion as AnyObject)
case .writingDirection(let directions):
return (NSWritingDirectionAttributeName, (directions.map{ $0.rawValue } as! AnyObject))
case .direction(let direction):
return (NSVerticalGlyphFormAttributeName, direction.rawValue as AnyObject)
}
}
}
Loading

0 comments on commit ec56370

Please sign in to comment.