Devang
Devang

Reputation: 11338

iphone : How to draw line on Label?

I want to make my label as shown in the image

enter image description here

I know I can get this effect by putting image view on it.

but is there any other method to do ?

How can I put line on label ?

Upvotes: 2

Views: 1553

Answers (5)

priyanka
priyanka

Reputation: 2076

Place a UIImageView with line image on your label so when you run application it will fit.

Upvotes: 0

Guntis Treulands
Guntis Treulands

Reputation: 4762

For one of my projects I've created an UILabel subclass, which supports multiline text, underline, strikeout, underline/strikeout line offset, different text alignment and different font sizes.

Please see provided link for more info and usage example.

https://github.com/GuntisTreulands/UnderLineLabel

Upvotes: 0

Nitish
Nitish

Reputation: 14113

Try this,

UILabel *blabel = [[UILabel alloc] initWithFrame:CGRectMake(XX, 6, 271, 26)];
blabel.text = @"Hellooooooo";
blabel.textAlignment = UITextAlignmentCenter;
blabel.backgroundColor = [UIColor clearColor];
blabel.textColor = [UIColor blackColor];
blabel.font = [UIFont systemFontOfSize:14];
[scrollDemo addSubview:blabel];

//underline code
CGSize expectedLabelSize = [@"Hellooooooo" sizeWithFont:blabel.font constrainedToSize:blabel.frame.size lineBreakMode:UILineBreakModeWordWrap];

UIView *viewUnderline=[[UIView alloc] init];
viewUnderline.frame=CGRectMake((blabel.frame.size.width - expectedLabelSize.width)/2,    expectedLabelSize.height + (blabel.frame.size.height - expectedLabelSize.height)/2,   expectedLabelSize.width, 1);
viewUnderline.backgroundColor=[UIColor blackColor];
[scrollDemo addSubview:viewUnderline];
[viewUnderline release]; 

The line above will appear below the text. You just need to change Y for UIView and it'll do wonders :)

Upvotes: 2

Maulik
Maulik

Reputation: 19418

you can create UIView with line's height and width and give background color to it. Put UIView over your UILabel .

Upvotes: 0

jussi
jussi

Reputation: 2216

put another label with "_" over it transparent background.

Upvotes: 0

Related Questions