Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let string = "کیخسروی"
- let font = UIFont(name: "IranNastaliq", size: 30)!
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineBreakMode = .byWordWrapping
- paragraphStyle.alignment = .center
- let attributes: [NSAttributedStringKey: Any] = [
- .font: font,
- .paragraphStyle: paragraphStyle
- ]
- let mutabbleAttributedString = NSMutableAttributedString(string: string, attributes: attributes)
- let rectSize = mutabbleAttributedString.size()
- let label = UILabel(frame: CGRect(x: 0, y: 0, width: rectSize.width, height: rectSize.height))
- label.font = font
- label.attributedText = mutabbleAttributedString
- label.backgroundColor = UIColor.yellow
- label.textAlignment = .center
- let size = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
- let width = label.sizeThatFits(size).width
- let height = label.sizeThatFits(size).height
- let frame = CGRect(x: 0, y: 0, width: width, height: height)
- label.frame = frame
- self.myView.addSubview(label)
- label.center = self.myView.center
Add Comment
Please, Sign In to add comment