2011-09-30 58 views
2

我想讓我的標籤,如下圖所示iphone:如何在標籤上畫線?

enter image description here

在我知道我可以通過把圖像視圖上得到這個效果。

但有沒有其他方法可以做?

我怎樣才能把標籤上的線?

回答

0

UIImageView與行標籤放在您的標籤上,因此當您運行應用程序時,它將適合。

0

把另一個標籤與 「_」 在它 透明背景。

0

您可以使用線條的高度和寬度創建UIView併爲其提供背景顏色。把UIView放在你的UILabel上。

2

試試這個,

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]; 

以上的行會出現下面的文字。你只需要改變Y表示的UIView,它會做的奇蹟:)

0

爲我的項目之一,我已經創建了一個的UILabel子類,它支持多行文本下劃線三振 ,下劃線/三角線偏移量,不同文本比對和不同字體大小

請參閱提供的鏈接瞭解更多信息和用法示例。

https://github.com/GuntisTreulands/UnderLineLabel