Skip to content

Conversation

@m1ga
Copy link
Contributor

@m1ga m1ga commented Oct 3, 2023

Currently the attributedString link is not very flexible in terms of color and removing the underline.

This PR adds two new features:

  • linkColor for the label: allows to set the color of the autoLink or attributedString link. Note: currently we can use another attribute Ti.UI.ATTRIBUTE_FOREGROUND_COLOR to color the link. This works for both Android and iOS. But there is not way to color a link with autoLink (Android only). So we won't need iOS parity for this property.

  • a new attribute underline in the attributedString that can be used in combination with type: Titanium.UI.ATTRIBUTE_LINK to remove the underline from the link

Screenshot_20231003-181037

var win = Titanium.UI.createWindow({
	layout: "vertical"
});
win.open();
var text = 'just one link';

var attr = Titanium.UI.createAttributedString({
	text: text,
	attributes: [{
		type: Titanium.UI.ATTRIBUTE_LINK,
		value: "https://titaniumsdk.com",
		range: [text.indexOf('one'), ('one').length],
		underline: false
	}]
});

// custom link color - attributedString
var label = Titanium.UI.createLabel({
	height: Titanium.UI.SIZE,
	attributedString: attr,
	linkColor: "red"
});

// custom link color - autoLink
var label2 = Titanium.UI.createLabel({
	height: Titanium.UI.SIZE,
	text: " this is a https://titaniumsdk.com test",
	linkColor: "blue",
	autoLink: true
});

// current default link color
var label3 = Titanium.UI.createLabel({
	height: Titanium.UI.SIZE,
	text: " this is a https://titaniumsdk.com test",
	autoLink: true
});

win.add([label, label2, label3]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants