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 set border top or bottom line on Label?

I want to show a horizontal line, it seems like <hr> on html.

<html>
<body>
<div>.... #######</div>
<hr />
<div>.... #######</div>
</body>
</html>

app.js

var label = Ti.UI.createLabel({borderWidth:1}); //this display four sides

// how to just show border top?

Can anyone help with this?

Thanks.

— asked November 25th 2010 by becca zhang
  • border
  • layout
0 Comments

5 Answers

  • I solve with this,

    
        var separator = Ti.UI.createView({
    
            width:'100%',
            height:1,
            backgroundColor:'white',
    
            bottom:0,
    
        });
    
    — answered November 12th 2012 by Christian Vazquez
    permalink
    0 Comments
  • you can't.
    can you eventually add a 1px high View Object with a backgroundColor to your label? - didn't test it tho…

    — answered November 25th 2010 by marcin kolonko
    permalink
    1 Comment
    • nope, doesn't work…

      — commented November 25th 2010 by marcin kolonko
  • Have you tried to use a background image? labelname.backgroundImage

    — answered November 25th 2010 by Daniel Ander
    permalink
    0 Comments
  • Becca

    You should not add a view to a label, as another poster has suggested. Certainly in android, this is not supported.

    To achieve your goal, you need to create a 1px-high (or however thick you would like your line) view and position it directly above your label.

    If you need to be able to move the label and the line around and for them to stay together, then either set the container view (or window) with a vertical layout and add the label to the container directly after the line. Alternatively, add both the line and the label to a view, and move that around instead.

    Hope this helps

    — answered November 25th 2010 by Paul Dowsett
    permalink
    0 Comments
  • I solve this by making an hr constructor like this:

    hr = () ->
        _view = Titanium.UI.createView({
            width: "100%"
            height: 1
            borderWidth: 1
            borderColor: "blue"
            })
            return _view
    

    then I add it anywhere I need one
    *note that I am using coffee script

    — answered July 18th 2012 by Brian Hurlow
    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.