在我的情況來計算一個UILabel frame.origin.x下面代碼,使其在右側:如何計算frame.size.width
writerNameLabel.frame = CGRectMake(cell.frame.size.width - writerNameLabel.frame.size.width - 80.......)
NSLog(@" writerNameLabel frame width: %f",writerNameLabel.frame.size.width);
NSLog(@" cell frame width: %f",cell.frame.size.width);
NSLog(@" cell - writerNameLabel frame width: %f",cell.frame.size.width - writerNameLabel.frame.size.width);
NSLog(@" writerNameLabel frame x: %f",writerNameLabel.frame.origin.x);
2012-08-17 14:43:36.895 writerNameLabel frame width: 38.000000
2012-08-17 14:43:36.899 cell frame width: 320.000000
2012-08-17 14:43:36.902 cell - writerNameLabel frame width: 282.000000
2012-08-17 14:43:36.904 writerNameLabel frame x: 240.000000
----
2012-08-17 14:43:36.924 writerNameLabel frame width: 102.000000
2012-08-17 14:43:36.928 cell frame width: 320.000000
2012-08-17 14:43:36.931 cell - writerNameLabel frame width: 218.000000
2012-08-17 14:43:36.934 writerNameLabel frame x: 240.000000
的問題是,這
cell.frame.size.width - writerNameLabel.frame.size.width
在我的計算不工作的一部分,它只是返回的
值cell.frame.size.width - 80
,爲什麼呢?我做錯了什麼嗎?
請指教。謝謝。
你有一個框架已經爲您的標籤嗎?如果不是,則默認爲{0,0,0,0}。 – 2012-08-17 06:58:13