Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.13 KB | None | 0 0
  1. func attributedUrlStringWith(link: URL,
  2.                                  font: UIFont?,
  3.                                  color: UIColor,
  4.                                  lineHeight: CGFloat = 0,
  5.                                  alignment: NSTextAlignment = .left) -> NSAttributedString? {
  6.         guard let font = font else {
  7.             assertionFailure("Error creating attributed string. Reason: provided font is nil. \nString: \(self)")
  8.             return nil
  9.         }
  10.        
  11.         let paragraphStyle = NSMutableParagraphStyle()
  12.         paragraphStyle.alignment = alignment
  13.  
  14.         if lineHeight != 0 {
  15.             paragraphStyle.minimumLineHeight = lineHeight
  16.         }
  17.         let attributes: [NSAttributedStringKey: Any] = [.paragraphStyle: paragraphStyle,
  18.                                                         .font: font,
  19.                                                         .foregroundColor: color,
  20.                                                         .link: link]
  21.        
  22.         let attributedString = NSAttributedString(string: self, attributes: attributes)
  23.        
  24.         return attributedString
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement