[TIMOB-19165] Cannot style links in Attributed Strings
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-04-21T08:06:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.2.1 |
Components | iOS |
Labels | TCSupportTriage, attributedString, color, links, underline |
Reporter | Fokke Zandbergen |
Assignee | Angel Petkov |
Created | 2014-11-12T13:57:18.000+0000 |
Updated | 2016-04-21T08:06:44.000+0000 |
Description
The following test case shows you cannot override the color and underlining of links in Attributed Strings. It doesn't matter if you add the link before or after styling the same (or part of) the text you make a link.
I'd like to change the color and remove the underline.
Test Case
var win = Titanium.UI.createWindow({
backgroundColor: '#ddd',
});
win.add(Ti.UI.createLabel({
top: 100,
attributedString: Ti.UI.iOS.createAttributedString({
text: 'Appcelerator always blue and underlined',
attributes: [
{
type: Ti.UI.iOS.ATTRIBUTE_LINK,
value: 'http://www.appcelerator.com',
range: [0, 12]
},
{
type: Ti.UI.iOS.ATTRIBUTE_FOREGROUND_COLOR,
value: 'red',
range: [0, 12]
},
{
type: Ti.UI.iOS.ATTRIBUTE_UNDERLINES_STYLE,
value: Ti.UI.iOS.ATTRIBUTE_UNDERLINE_STYLE_NONE,
range: [0, 12]
}]
})
}));
win.open();
Curious, any updates on this? Seems like a pretty common thing to want to update the color of a link to match your app's interface...
Still nothing on this? :-(
Hi all, please note that: {quote} ON iOS, Titanium.UI.ATTRIBUTE_LINK only supported on
I hope this doesn't mean the issue is closed... Titanium.UI.ATTRIBUTE_LINK does work on Ti.UI.Label, only that you cannot change underline and color. Without being able to override the styling, it becomes unusable in almost all use cases, no matter if the property is applied to a textfield, textarea or label.
Maybe, if someone would wrap this module for Titanium, it would be solved: https://github.com/TTTAttributedLabel/TTTAttributedLabel ? Via http://stackoverflow.com/questions/15381028/make-link-in-uilabel-attributedtext-not-blue-and-not-underlined?answertab=active#tab-top
The module [~arif] linked does seem to give a hint on how we can implement this: * https://github.com/TTTAttributedLabel/TTTAttributedLabel/blob/master/TTTAttributedLabel/TTTAttributedLabel.m#L427-L429 * https://github.com/TTTAttributedLabel/TTTAttributedLabel/blob/master/TTTAttributedLabel/TTTAttributedLabel.m#L650-L652
I ran into this issue recently and it was quite frustrating. Fortunately, there is a sort of workaround, albeit it is extremely ugly. You are able to change the underline color on the link. So what I did was have a background label and a foreground label, each one with the exact same text. In the background label, you add the link with the unchangeable text color, and then in the foreground, you use the attributed string to paint over the actual link with text colored to the actual color you want it. This allows you to still use the link functionality in the label but also "change" its color. It would be great if this gets fixed soon since that workaround is very ugly, but I guess it does work for most use-cases.
[~dfoxinator] we are looking into this issue this very moment and hope to add it soon.
Thanks, that's great news.
[~dfoxinator] Hello David, working on a fix for the issue currently. I apologise with the delay , should be fixed very soon, thank you for the patience!.
Hello , the issue should be fixed now. The ability to set a color for an NSlink isn't actually supported by apples delegate however we've created a workaround the issue. So setting the color,underline style,color or any attributed string property can be set. Use the code provided to test. Expected result: Clicking any of the 2 urls should open a webView with the website hyperlinked. PR : https://github.com/appcelerator/titanium_mobile/pull/7645
Was anything resolved with this as it doesn't work for me SDK 5.1.2GA? Thanks
[~samueleast] It is in review and will be part of 5.2.0 or 5.2.1
Awesome thanks fokke ;)
New PR here: https://github.com/appcelerator/titanium_mobile/pull/7751 as Angel closed the earlier one in favor of this one.
I want very much, it will be part of 5.2.0. Thank you.
PR(5_2_X):https://github.com/appcelerator/titanium_mobile/pull/7771
[~engross] it will be part of 5.2.1
[~apetkov] how exactly will this PR allow you to set the color for the link. In the PR I see it hard coded to blue? Will setting a color on the same range override that?
[~fokkezb] If you don't give the link a color or any other property it will default to blue. If a color is passed in it will override the base color and set it to wherever was passed in If.if its in the same range, like you said. If you run my example code with the master branch SDK , as the changes are merged there you will see the first link is red with no underline. Thanks :).
Thanks [~apetkov]!
Verified fixed, using: MacOS 10.11.3 (15D21) Studio 4.5.0.201602170821 Ti SDK 5.2.1.v20160223221727 Appc NPM 4.2.3 Appc CLI 5.2.0 Alloy 1.7.33 Xcode 7.2 (7C68) Links can be styled in attributed strings by setting specific attributes for the link ranges (underscore, color, link). Tested using the provided test cases.
I tested this on my project on 5.2.1 latest RC and the fix seems to work perfectly. Thanks!
[~bimmel] this issue is listed in https://wiki.appcelerator.org/display/~bimmel/Titanium+SDK+5.3.0.Beta+Release+Note#TitaniumSDK5.3.0.BetaReleaseNote-CommunityCredits but was already fixed in 5.2.1 [~cng] why do issues sometimes have 2 fix versions?
So that if it could make it in time for the earlier version great, if not, the second version is a must. In this case, we forgot to remove the second fix version because it actually made it in time. Please comment on Brian's release notes to inform him of the change.