Guest User

Untitled

a guest
Jan 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. let string = "کیخسروی"
  2. let font = UIFont(name: "IranNastaliq", size: 30)!
  3. let paragraphStyle = NSMutableParagraphStyle()
  4. paragraphStyle.lineBreakMode = .byWordWrapping
  5. paragraphStyle.alignment = .center
  6.  
  7. let attributes: [NSAttributedStringKey: Any] = [
  8. .font: font,
  9. .paragraphStyle: paragraphStyle
  10. ]
  11.  
  12.  
  13. let mutabbleAttributedString = NSMutableAttributedString(string: string, attributes: attributes)
  14. let rectSize = mutabbleAttributedString.size()
  15. let label = UILabel(frame: CGRect(x: 0, y: 0, width: rectSize.width, height: rectSize.height))
  16. label.font = font
  17. label.attributedText = mutabbleAttributedString
  18. label.backgroundColor = UIColor.yellow
  19. label.textAlignment = .center
  20. let size = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
  21. let width = label.sizeThatFits(size).width
  22. let height = label.sizeThatFits(size).height
  23. let frame = CGRect(x: 0, y: 0, width: width, height: height)
  24. label.frame = frame
  25. self.myView.addSubview(label)
  26. label.center = self.myView.center
Add Comment
Please, Sign In to add comment