Skip to content

Instantly share code, notes, and snippets.

@samueleastdev
Created September 30, 2016 10:30
Show Gist options
  • Save samueleastdev/dffea5870613d7c9e0979f9a846fcbff to your computer and use it in GitHub Desktop.
Save samueleastdev/dffea5870613d7c9e0979f9a846fcbff to your computer and use it in GitHub Desktop.
Appcelerator Ti.UI.ATTRIBUTE_LINK with link color set.
var termsText = L('terms_and_policy', 'No Translation');
if (OS_IOS) {
var attr = Ti.UI.createAttributedString({
text : termsText,
attributes : [{
type : Ti.UI.ATTRIBUTE_LINK,
value : "terms",
range : [termsText.indexOf('Terms of Use'), ('Terms of Use').length]
}, {
type : Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
value : "red",
range : [termsText.indexOf('Terms of Use'), ('Terms of Use').length]
}, {
type : Ti.UI.ATTRIBUTE_UNDERLINE_COLOR,
value : "red",
range : [termsText.indexOf('Terms of Use'), ('Terms of Use').length]
}, {
type : Ti.UI.ATTRIBUTE_LINK,
value : "policy",
range : [termsText.indexOf('Privacy Policy'), ('Privacy Policy').length]
}, {
type : Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
value : "red",
range : [termsText.indexOf('Privacy Policy'), ('Privacy Policy').length]
}, {
type : Ti.UI.ATTRIBUTE_UNDERLINE_COLOR,
value : "red",
range : [termsText.indexOf('Privacy Policy'), ('Privacy Policy').length]
}]
});
$.termsAndConditionsText.attributedString = attr;
$.termsAndConditionsText.addEventListener('link', function(_event) {
switch (_event.url) {
case "terms":
console.log("open terms window");
break;
case "policy":
console.log("open policy window");
break;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment