Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. func setAttributes(price : String)-> NSAttributedString {
  2. let font:UIFont? = UIFont.boldSystemFont(ofSize: 22)
  3. let fontSuper:UIFont? = UIFont.boldSystemFont(ofSize: 15)
  4. let aDotRange = (price as NSString).range(of: ".")
  5.  
  6. let attString:NSMutableAttributedString = NSMutableAttributedString(string: price, attributes: [.font:font!])
  7.  
  8. attString.setAttributes([.font:fontSuper!,.baselineOffset:5], range: NSRange(location:0,length:1))
  9.  
  10. attString.setAttributes([.font:fontSuper!,.baselineOffset:5],
  11. range: NSRange(location:aDotRange.location,length:4))
  12. attString.setAttributes([.font:font!],
  13. range: NSRange(location:1,length:aDotRange.location - 1 ))
  14. attString.setAttributes([.font:fontSuper!],
  15. range: NSRange(location:aDotRange.location + 4,
  16. length: (price.count) - (aDotRange.location + 4) ))
  17. return attString
  18. }
  19.  
  20. lblPrice.attributedText = self.setAttributes(price: "$249.99 / mon")
  21. lblPrice.layer.cornerRadius = 4
  22. lblPrice.layer.borderWidth = 1.0
  23. lblPrice.layer.borderColor = UIColor.blue.cgColor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement