Closed dhirajdebut closed 6 years ago
hi @dhirajdebut , you should use this atts[NSAttributedStringKey.underlineStyle] = NSUnderlineStyle.styleSingle.rawValue instead of atts[NSAttributedStringKey.underlineStyle.rawValue] = NSUnderlineStyle.styleSingle Hope this help.
0.8.1 crash
label.configureLinkAttribute = { (type, attributes, isSelected) in
var retDic = attributes
switch type {
case customType:
retDic[NSAttributedStringKey.underlineStyle] = NSUnderlineStyle.styleThick
let paragraph = NSMutableParagraphStyle()
paragraph.lineSpacing = 5
retDic[NSAttributedStringKey.paragraphStyle] = paragraph
}
return retDic
}
crash!!
but if you
label.configureLinkAttribute = { (type, attributes, isSelected) in
var retDic = attributes
switch type {
case customType:
// retDic[NSAttributedStringKey.underlineStyle] = NSUnderlineStyle.styleThick
// let paragraph = NSMutableParagraphStyle()
// paragraph.lineSpacing = 5
// retDic[NSAttributedStringKey.paragraphStyle] = paragraph
retDic[NSAttributedStringKey.font] = UIFont.mg.m14
default: break
}
return retDic
}
run well
i've encountered this as well but haven't had a chance to look into it. the underline renders after there's interaction, so it works! but i believe there just needs to be a style check or layout performed after initialization and link attribution is configured.
fileprivate lazy var _label: ActiveLabel = {
let label = ActiveLabel()
let labelText = "hello"
let helloType = ActiveType.custom(pattern: labelText)
label.handleCustomTap(for: helloType, handler: { (string) in
// action
})
label.numberOfLines = 3
label.textAlignment = .center
label.textColor = UIColor.white
label.customColor = [helloType : UIColor.orange]
label.enabledTypes = [helloType]
label.text = "hello is an underlined link"
label.configureLinkAttribute = { (type, attributes, isSelected) in
var atts = attributes
atts[NSAttributedStringKey.underlineStyle] = NSUnderlineStyle.styleThick.rawValue
return atts
}
return label
}()
solution: if you set the text following configureLinkAttribute, then it works.
Feel free to re-open this issue.
Hi,
I am trying to underline particular words in a string. I have tried below code but it does not work.