Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.69 KB | None | 0 0
  1. enum TextAttribute {
  2.   case foregroundColor(NSColor)
  3.   case link(URL)
  4.   case kerning(Int)
  5.   case underline(NSUnderlineStyle)
  6.   case custom(key: String, value: Any)
  7.  
  8.   var name: String {
  9.     switch self {
  10.       case .foregroundColor:
  11.         return "NSForegroundColorAttributeName"
  12.  
  13.       case .link:
  14.         return "NSLinkAttributeName"
  15.  
  16.       case .kerning:
  17.         return "NSKernAttributeName"
  18.  
  19.       case .underline:
  20.         return "NSUnderlineStyleAttributeName"
  21.  
  22.       case let .custom(key, _):
  23.         return key
  24.  
  25.     }
  26.   }
  27. }
  28.  
  29. let string = NSAttributedString(string: "My underlined link", attributes: [
  30.   .custom(key: "myCustomAttribute", value: 5),
  31.   .link(myWebsiteURL)
  32. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement