Want to add left margin spacing with NSMutableAttributedString
NSMutableParagraphStyle
& firstLineHeadIndent
but no luck, firstLineHeadIndent
or headIndent
does't take effect
my implementation:
lazy var priseField: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 15)
label.textColor = .black
let string = self.addMutableAttribute(string: "50")
string.append(self.addAttribute(string: "lari"))
label.attributedText = string
return label
}()
func addMutableAttribute(string:String = "") -> NSMutableAttributedString {
let attribute:[NSAttributedString.Key : Any] = [ NSAttributedString.Key.foregroundColor: UIColor.black,
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]
let attrString = NSMutableAttributedString(string: string, attributes: attribute)
return attrString
}
func addAttribute(string:String = "") -> NSMutableAttributedString {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.firstLineHeadIndent = 3;
paragraphStyle.headIndent = 3
let attribute:[NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.darkGray,
.paragraphStyle: paragraphStyle,
.font: UIFont.boldSystemFont(ofSize: 12),
.baselineOffset: 1
]
let attrString = NSMutableAttributedString(string: string, attributes: attribute)
return attrString
}
and result is:
I want to improve space between 50 and lari