Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18407] Attributed Text: Ti.UI.ATTRIBUTE_FONT not working

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2015-01-21T17:26:26.000+0000
Affected Version/sRelease 4.0.0
Fix Version/sRelease 4.0.0
ComponentsAndroid, iOS
Labelsn/a
ReporterBenjamin Hatfield
AssigneeChee Kiat Ng
Created2015-01-19T22:54:12.000+0000
Updated2015-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

FileDateSize
SDK3_5_0.png2015-01-19T22:54:12.000+0000123535
SDK3_6_0_Android.png2015-01-19T22:54:12.000+000090996
SDK3_6_0_iOS.png2015-01-19T22:54:13.000+0000109241

Comments

  1. Ingo Muschenetz 2015-01-19

    FYI
  2. Chee Kiat Ng 2015-01-19

    [~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:
       value: { font:{fontSize: 24, fontFamily: 'Helvetica Neue' }}
       
  3. Benjamin Hatfield 2015-01-20

    [~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.
  4. Chee Kiat Ng 2015-01-20

    [~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.
  5. Chee Kiat Ng 2015-01-20

    PR Here: https://github.com/appcelerator/titanium_mobile/pull/6590
  6. Ewan Harris 2015-01-21

    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.

JSON Source