-
Notifications
You must be signed in to change notification settings - Fork 3
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
Support mapping for attributes of range #3
Comments
@gregpardo Thanks for the kind words! I like your proposed idea a lot, and can see why it would be really useful! Has me thinking we can achieve this with some functional composition. How about we brainstorm on an ideal syntax let builder = NSAttributedStringAttributeBuilder()
builder.setAttribute(.Font(UIFont.systemFontOfSize(12)))
let multiString: NSAttributedString =
"This is regular text"
>>> builder
>>> "this is bold text."
>>> builder.setAttribute(.Font(UIFont.boldSystemFontOfSize(12)))
>>> "this is regular text again"
>>> builder.setAttribute(.Font(UIFont.systemFontOfSize(12))) |
Perhaps sticking with the same style syntax is possible.... let attributedString = NSAttributedString.make( { (make: NSAttributedStringAttributeBuilder) -> Void in
make.nextString("This is regular text")
make.setAttribute(.Font(UIFont.systemFontOfSize(12)))
make.nextString("This is bold text")
make.setAttribute(.Font(UIFont.boldSystemFontOfSize(12)))
make.nextString("This is regular text again")
make.setAttribute(.Font(UIFont.systemFontOfSize(12)))
}) Basically it could work like this
Some other ideas for methods.
I could see situations where you would want to keep the last set of attributes and mutate them. By default it should probably clear every time a nextString occurs.
Force a fresh set of attributes
Appends a group of attributes. Any existing attributes with same keys will be overwritten
Remove an existing attribute I like the functional approach but maybe that would be a good optional syntax. Closures seem to be a pretty standard swift idea. Let me know your thoughts and love/hate on any ideas here. |
Sorry for the delay getting back! Read through your proposal, love it all! Seems well thought out and like it would be super useful! I liked this idea a lot too: we could even pair the syntax closely to For the actual storing of strings as we build them:
I am wondering if there is any merit in internally using multiple Then you could just do a I say go for which ever approach! I'm excited to have this addition to the library, thanks for your effort! |
https://github.com/gregpardo/Verona/tree/develop Let me know if you have suggestions. I haven't updated any tests or anything like that yet. |
Looking great so far! go on a head and pull request that back and i'll add a few comments 👍 awesome work! On the note of testing, are you familiar with snapshot tests? |
I just got back into iOS and I don't think that project was around when I was working on it before. So not really but I did look into a little bit. |
Being addressed here: #6 Will close this issue after merged 👍 |
So I really like this project. I've been looking for something like it. I would like to suggest a feature. Sometimes you need attributes that are over the entire string...
What I'm proposing, and maybe I can help with, is an easy way to build strings like this in some sort of chainable way.
Perhaps a new extension can be created similar to 'make' or we can extend make to check for types and pass it an array of '(make: NSAttributedStringAttributeBuilder)' and at the concat all the strings together and return.
The text was updated successfully, but these errors were encountered: