2012-06-29 26 views

回答

1

解決方法是正常創建UILabel,然後將黑色UIView放在UILabel的空白部分的頂部。根據文字字體的大小,你實際上可以計算出應該放在哪裏。

+0

我只想把綠色背景放到UIlabel – samir

+0

'[myLabel setBackgroundColor:[UIColor greenColor]];' – Peres

+0

héhéima對不起,我英文不好,怎麼可以像圖片一樣? – samir

1

一個解決辦法是添加一個UILabel作爲包裝的UIView的子視圖

// Using ARC 

// Set Wrapper 
CGRect wrapperFrame = CGRectMake(0, 0, 320, 80); 
UIView *specialLabel = [[UIView alloc] initWithFrame:wrapperFrame]; 
[specialLabel setBackgroundColor:[UIColor blackColor]]; 

// Set Content 
CGFloat padding = 10; 
CGRect contentFrame = CGRectInset(wrapperFrame, padding, padding); 
UILabel *contentLabel = [[UILabel alloc] initWithFrame:contentFrame]; 
[contentLabel setBackgroundColor:[UIColor greenColor]]; 

// Append content to wrapper 
[specialLabel addSubview:contentLabel];