rubymotion-community / sugarcube

Some sugar for your cocoa. RubyMotion helpers.
Other
422 stars 66 forks source link

Adding actions to NSAttributedString similar to a button with UITapGestureRecognizer #80

Closed travisvalentine closed 11 years ago

travisvalentine commented 11 years ago

I'm using sugarcube-attributedstring in a project and am loving it. However, I'm wondering if there is a way to add actions to the links in the same way I can add them to regular UILabels by using userInteractionEnabled, UITapGestureRecognizer, and addGestureRecognizer. Below is an example of the NSAttributedString syntax I'm working with:

@profile.attributedText = (("Likes ".attrd +
                             "#{user[:activity_1]}".attrd.link("http://www.google.com").underline_color(UIColor.clearColor) +
                             "and " +
                             "#{user[:activity_2]}".attrd.link("http://www.google.com").underline_color(UIColor.clearColor)))
colinta commented 11 years ago

Near as I can tell, this is impossible; you can add gesture recognizers, of course, but NSAttributedStrings on iOS cannot include links. The NSLinkAttributeName setting is missing. :frowning:

travisvalentine commented 11 years ago

Gotcha, thanks @colinta. Just out of curiosity, in the above example how could I best add gesture recognizers to user[:activity_1] and user[:activity_2]?

colinta commented 11 years ago

You won't be able to add gestures to those individual links, so I think the way to do this would be to use a UIWebView, or TTTAttributedLabel, which is meant for this kinda thing.