I'm having some issues with a bullet point list on an attributed string. I need to have a custom icon and it needs to be a bit bigger than the rest of the text. However, when I change its font size the line's height get bigger than the rest which leads to a pretty messed up layout.
I already tried tinkering the NSMutableParagraphStyle but didn't have much luck. Any leads on what should I try next? Thanks.
do {
let attrStr = try NSMutableAttributedString(data:d, options:o, documentAttributes:nil)
let stringToUpdate = attrStr.mutableString.replacingOccurrences(of: "•", with: "☞")
attrStr.mutableString.setString(stringToUpdate)
let regex = try! NSRegularExpression(pattern: "☞", options: [])
let range = NSMakeRange(0, stringToUpdate.characters.count)
let fontIcon = UIFont(name: fontName, size: fontSize + 16)! //TODO: change
regex.enumerateMatches(in: stringToUpdate, options: [], range: range, using: { (result, flags, stop) in
if let subStringRange = result?.rangeAt(0) {
attrStr.addAttribute(NSFontAttributeName, value: fontIcon , range: subStringRange)
attrStr.addAttribute(NSBaselineOffsetAttributeName, value: -8, range: subStringRange)
}
})
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.addTabStop(NSTextTab(textAlignment: .left, location: 1.0, options: [:]))
paragraphStyle.firstLineHeadIndent = 0
paragraphStyle.headIndent = 56;
paragraphStyle.defaultTabInterval = 2.0
paragraphStyle.minimumLineHeight = 1
paragraphStyle.maximumLineHeight = 1
paragraphStyle.lineHeightMultiple = 1
paragraphStyle.lineSpacing = 10
paragraphStyle.paragraphSpacing = 40
paragraphStyle.paragraphSpacingBefore = 10
attrStr.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, stringToUpdate.characters.count))
return attrStr
}