Skip to content

Commit cb69378

Browse files
authored
docs: attributedString link example (#14056)
* docs: attributedString link example * docs: attributedString link example
1 parent f5dfa92 commit cb69378

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

apidoc/Titanium/UI/AttributedString.yml

+60
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,63 @@ examples:
133133
134134
win.add(label);
135135
```
136+
- title: Links with underline color.
137+
example: |
138+
``` js
139+
const win = Ti.UI.createWindow({
140+
backgroundColor: 'gray',
141+
layout: 'vertical'
142+
});
143+
const lbl_a = createLink();
144+
const lbl_b = createLink();
145+
146+
colorLink(lbl_b);
147+
148+
win.add([lbl_a, lbl_b]);
149+
win.open();
150+
151+
function createLink() {
152+
const label = Ti.UI.createLabel({
153+
top: 20,
154+
attributedString: Ti.UI.createAttributedString({
155+
text: 'Check out Titanium SDK',
156+
attributes: [{
157+
type: Ti.UI.ATTRIBUTE_LINK,
158+
value: 'https://titaniumsdk.com',
159+
range: [10, 12]
160+
}]
161+
})
162+
});
163+
164+
label.addEventListener('link', e => {
165+
Ti.Platform.openURL(e.url);
166+
});
167+
168+
return label;
169+
}
170+
171+
function colorLink(lbl) {
172+
const attributedString = lbl.attributedString;
173+
const textColor = 'purple';
174+
const underlineColor = 'yellow';
175+
176+
for (const attribute of attributedString.attributes) {
177+
if (attribute.type === Ti.UI.ATTRIBUTE_LINK) {
178+
179+
// Set new link color.
180+
attributedString.addAttribute({
181+
type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
182+
value: textColor,
183+
range: attribute.range
184+
});
185+
186+
// Set new underline color.
187+
attributedString.addAttribute({
188+
type: Ti.UI.ATTRIBUTE_UNDERLINE_COLOR,
189+
value: underlineColor,
190+
range: attribute.range
191+
});
192+
}
193+
}
194+
}
195+
```

apidoc/Titanium/UI/UI.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ properties:
490490
491491
See <Attribute> for more information.
492492
type: Number
493-
platforms: [iphone, ipad, macos]
494-
since: "3.6.0"
493+
platforms: [android, iphone, ipad, macos]
494+
since: {iphone: "3.6.0", ipad: "3.6.0", android: "10.0.0"}
495495
permission: read-only
496496

497497
- name: ATTRIBUTE_STRIKETHROUGH_COLOR

0 commit comments

Comments
 (0)