[TIMOB-18407] Attributed Text: Ti.UI.ATTRIBUTE_FONT not working
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-01-21T17:26:26.000+0000 |
Affected Version/s | Release 4.0.0 |
Fix Version/s | Release 4.0.0 |
Components | Android, iOS |
Labels | n/a |
Reporter | Benjamin Hatfield |
Assignee | Chee Kiat Ng |
Created | 2015-01-19T22:54:12.000+0000 |
Updated | 2015-01-21T20:44:25.000+0000 |
Description
ENVIRONMENT
Mac OS X 10.9.5
Ti CLI: 3.5.0-dev
Titanium SDK 3.6.0.v20150119054128, 3.5.0.GA
Android 5.0, Genymotion emulator, Google Nexus 7 - 4.4.4 - API 19 - 800x1280
iOS 8.1, Xcode 6.1.1, iPhone 6+ simulator
REPRODUCTION:
Run the code below in the iOS simulator and Genymotion emulator using TiSDK 3.6.0.
ACTUAL RESULTS:
The label with the attributed string does not match the second label. See the 3.6.0 screenshots.
EXPECTED RESULTS:
Both labels should match. See the 3.5.0 screenshots.
OTHER INFO:
Using AttributedString with the iOS namespace works with 3.5.0.GA but has the same results with 3.6.0.
Change Ti.UI.createAttributedString to Ti.UI.iOS.createAttributedString and Ti.UI.ATTRIBUTE_FONT to Ti.UI.iOS.ATTRIBUTE_FONT
var win = Ti.UI.createWindow({
backgroundColor: '#999',
layout: 'vertical'
});
var text = "Have you tried hyperloop yet?";
var attr = Ti.UI.createAttributedString({
text: text,
attributes: [
{
type: Ti.UI.ATTRIBUTE_FONT,
value: { fontSize: 24, fontFamily: 'Helvetica Neue' },
range: [0, text.length]
}
]
});
var label = Ti.UI.createLabel({
attributedString: attr,
top: 50
});
var label2 = Ti.UI.createLabel({
top: 10,
font: { fontSize: 24, fontFamily: 'Helvetica Neue' },
text: text
});
win.add(label);
win.add(label2);
win.open();
Attachments
File | Date | Size |
---|---|---|
SDK3_5_0.png | 2015-01-19T22:54:12.000+0000 | 123535 |
SDK3_6_0_Android.png | 2015-01-19T22:54:12.000+0000 | 90996 |
SDK3_6_0_iOS.png | 2015-01-19T22:54:13.000+0000 | 109241 |
FYI
[~bhatfield], The way to use addAttribute is incorrect in the sample code. AttributedString requires to include "font" field in "value" when you use Ti.UI.ATTRIBUTE_FONT, as shown here:
[~cng], this changes the previous behavior with the iOS-specific namespace. Plus, you're wrapping the Font dictionary in another dictionary. I think it would be simpler just to pass the Font dictionary.
[~bhatfield], after some checking, you are right. the expected previous behavior is as you mentioned. I was a little misled because in the SDK, previous behavior wasn't working correctly at all. Will fix.
PR Here: https://github.com/appcelerator/titanium_mobile/pull/6590
Verified fix on: Mac OSX 10.10.1 Appcelerator Studio, build: 3.4.1.201410281743 Titanium SDK build: 3.6.0.v20150121092531 Titanium CLI, build: 3.4.1 Alloy: 1.5.1 Xcode 6.1.1 iPhone 6 Plus (8.1), Nexus 5 (5.0) Using the code provided built to device, both of the labels now display with the same attributed text. Closing ticket.