【发布时间】:2009-01-02 07:00:37
【问题描述】:
如何修改 iPhone Developer's Cookbook 第 6 章中“09a - PrefsTable”配方中的以下 sn-p(在 tableView:cellForRowAtIndexPath: UITableViewController 方法中):
if (row == 1) {
// Create a big word-wrapped UILabel
cell = [tableView dequeueReusableCellWithIdentifier:@"libertyCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"libertyCell"] autorelease];
[cell addSubview:[[UILabel alloc] initWithFrame:CGRectMake(20.0f, 10.0f, 280.0f, 330.0f)]];
}
UILabel *sv = [[cell subviews] lastObject];
sv.text = @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
sv.textAlignment = UITextAlignmentCenter;
sv.lineBreakMode = UILineBreakModeWordWrap;
sv.numberOfLines = 9999;
return cell;
}
...调整“sv”UILabel 子视图和“单元格”UITableViewCell 的大小,使其大小刚好适合文本(并使用或多或少的文本,以及其他类型的文本对齐方式)?我查看了 UILabel textRectForBounds:limitedToNumberOfLines: 方法,但文档指出它不应该直接调用(并且应该只被覆盖)。我尝试了 UIView sizeToFit 方法,但没有成功。
【问题讨论】:
-
+1 表示选择的例句。
标签: cocoa-touch