-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding custom attributes? #9
Comments
Update Subclassing to provide an attribute works, but seems very hacky. Is there a better way? class CustomCodeAttributedString: CodeAttributedString {
override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [String : Any]
{
var attributes = super.attributes(at: location, effectiveRange: range)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 30
paragraphStyle.alignment = .center
attributes[NSParagraphStyleAttributeName] = paragraphStyle
return attributes
}
} |
Hi @droidery, there's no support for that right now, but I can totally add this on a future release. CodeAttributedString will dynamically add attributes to the text, and this as a side effect will remove the current attributes of the line being processed. I will need to take some time to think of a proper solution, but for now I think your approach is the best one. |
@raspu I would definitely love a solution for this! But it's been so long since this was requested. Is there at least a way for us to hardcode the font we want throughout the whole themes and parsing? If there's that option we can force a font there. |
@ivan-cantarino You will need to call |
2019 / Swift 4.2 version of ghost's code snipplet from above: class CustomCodeAttributedString: CodeAttributedString {
override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [AttributedStringKey : Any] {
var attributes = super.attributes(at: location, effectiveRange: range)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 30
paragraphStyle.alignment = .center
attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle
return attributes
}
} |
I'm having a bit of trouble adding my own attributes to Highlightr.
When not using Highlightr, I can add attributes to a
UITextView
usingaddAttribute()
. What's a good way to add my own (e.g. for increasing line-height and changing the alignment programmatically)?This is the code which doesn't work (creating and adding an attribute). Normally "attempt 2" is all that's needed to add an attribute to a text view.
The text was updated successfully, but these errors were encountered: