2010-06-14 28 views
3

我有一個帶有兩個標籤的單元格。我如何以編程方式居中對齊頂部標籤並隱藏第二個標籤?如何在XCode中居中放置標籤的文本

+0

可能重複的[UILabel對齊文本到中心](http://stackoverflow.com/questions/5722730/uilabel-align-text-to-center) – royhowie 2015-05-26 04:33:57

回答

4

[labelOne setTextAlignment:UITextAlignmentCenter]; //以UILabel中的文本爲中心 [labelTwo setHidden:YES] //在那裏,但不可見。

8

UITextAlignmentCenter已棄用。你應該使用下列內容:

labelOne.textAlignment = NSTextAlignmentCenter; 
0

我認爲你正在試圖做的是: 事情是這樣的..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    firstLabel.frame = cell.frame; // or reconfigure your frame or some reason(i dont know) 
    firstLabel.textAlignment = NSTextAlignmentCenter; 
    secondLabel.hidden = YES; 
} 

你想你從firstLabel文本是在的中心細胞?

相關問題