appceleratorappcelerator-titanium

Is it possible to strike-through a Label's text in Appcelerator?


Is it possible to apply a strike-through to a Label's text in Appcelerator? If so, how?


Solution

  • Instead of using a Label you can use attributed string. Which offers quite some functionality.

    An example for Strikethrough is this:

    var attr = Ti.UI.createAttributedString({
        text: 'TEXT THAT NEEDS STRIKETHROUGH',
        attributes: [
            {
                type: Ti.UI.ATTRIBUTE_STRIKETHROUGH_STYLE,
                value: Ti.UI.ATTRIBUTE_UNDERLINE_STYLE_THICK, // Ignored by Android only displays a single line
                range: [text.indexOf('hyperloop'), ('hyperloop').length]
            }
        ]
    });
    

    Example is taken from the Attributed String Guide which is on the Appcelerator Documentation