Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to underline labels?

Hi All,
I was wondering what is the best way to underline a Label created by Titanium.UI.createLabel()

Thanks,
Ajay

— asked March 11th 2010 by Ajayshanker Krishnamurthy
  • Label
  • layout
  • ui
0 Comments

4 Answers

  • AFAIK, underline is not a supported style for native iPhone labels so I'd guess, that there's no way in Titanium. Don't know for Android, though.

    — answered March 12th 2010 by Stefan Matthias Aust
    permalink
    0 Comments
  • Worst case you can add a view with a height of 1 and the same width of the label placed directly under the label.

    — answered February 9th 2011 by Dan Boorn
    permalink
    2 Comments
    • I tried this before and could never get it to look right. If you have a code sample I'd love to see it.

      — commented February 9th 2011 by Frank A
    • Another way, although I don't know what type of performance hit it would cause, would be to use a webview with your text formatted the way you like in place of a label if you REALLY, REALLY had to have it underlined.

      — commented February 9th 2011 by Paul Arce
  • Hi,
    you can easily wrap your label with a view which calculates the size of the label after a certain timeout and adds a line view.

    function decorateLabel(label) {
      var decoratedView = Titanium.UI.createView({
        width : Titanium.UI.SIZE, height : Titanium.UI.SIZE, layout : 'vertical', left : 0
      });
      decoratedView.add(label);
    
      setTimeout(function() {
        var lineView = Titanium.UI.createView({
          width : label.getSize().getWidth(), left : label.left, height : 1, backgroundColor : label.color ? label.color : 'white', top : -1, bottom : 0
        });
        decoratedView.add(lineView);
      }, 100);
    
      return decoratedView;
    }
    
    — answered February 19th 2013 by Stefan Sommer
    permalink
    0 Comments
  • On iOS Titanium label does not support underline style (TiLabel is basically wrapped around the UILabel but doesnt utilise the attributedText). We've created a replacement for UILabel that supports underline along with other few goodies - you can try it here.

    — answered April 9th 2013 by Andrew Nisbet
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.