naldikt / NXSS

NX Style Sheet - customize your UI using CSS-like files & conventions.
1 stars 0 forks source link

AttributedString #26

Open naldikt opened 8 years ago

naldikt commented 8 years ago

We need to enable NXSS-supported NSAttributedString. The idea's to rapidly create strings without having to deal with the complexity of NSAttributedString.

Specs

For easiness of usage, I'd recommend to follow HTML standard tagging-system i.e.

"Enjoy your free trial? <nxss class='home-attr-signup'>Sign Up</nxss>. You will also get 25 <nxss class='icon-coin'></nxss>" 

(^ we're applying different style for Sign Up and put in coin-icon next to 25)

Why? With NSAttributedString, we need to specify index/range of the attributes to attach to. This may work by finding the substring programmatically (rangeOfString) , but it won't work well when the string is localized. By specifying the name of the NXSS class in the string, we can now easily parse the tags and figure out the start & end index.

This is similar to adenyes' current solution with HTML string, but we're utilizing NXSS framework to provide the styling.

Proposal

Create a new class NXSSAttributedString. This class is not a subclass of NSAttributedString. The input is the string containing NXSS tags. The output is NSAttributedString.

Complexity

How does this work with standard font-size declaration on a UILabel?