2013-03-08 47 views
-2

我用這個來設置爲textLabel在一個UITableViewCell的子視圖:爲textLabel作爲子視圖

UILabel *text = [[UILabel alloc] initWithFrame:(0, 275, 0, 0)]; 

[text setText:contentString]; 
[cell addSubview:text]; 

但文字不顯示。代碼有問題嗎?

回答

2
UILabel *text = [[UILabel alloc] initWithFrame:(0, 275, 50.0, 50.0)]; 
[text setText:contentString]; 
[cell addSubview:text]; 

使用此代碼:)

1

顯然....

UILabel *text = [[UILabel alloc] initWithFram:(0, 275, 0, 0)];

你給高度和標籤的寬度爲0

initWithFrame:(x-coordinate, y-coordinate, width, height) 
+0

O好吧,我想他們是0時,它是多行。嗯,這是一個可變的文本我可以設置高度變量的文本呢? – 2013-03-08 12:58:36

+0

對於多行,您需要設置該標籤的numberoflines屬性。 – 2013-03-08 12:59:50

+0

您可以參考此鏈接:http://stackoverflow.com/questions/6659923/a-generic-function-to-find-height-for-label-by-passing-the-string-that-the-label – 2013-03-08 13:03:29