Jak należałoby zmodyfikować następujący fragment (w Tableview: cellForRowAtIndexPath: metoda UITableViewController) z "09a - PrefsTable" receptury z rozdziału 6 iPhone programisty Cookbook:Jak dopasować UILabel do rozmiaru?
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;
}
... do wielkości po " sv "UILabel subview i" cell "UITableViewCell mają rozmiar wystarczająco duży, aby zmieścić tekst (i pracować z mniej więcej tekstem i innymi typami wyrównania tekstu)? Przyjrzałem się metodzie UILabel textRectForBounds: limitedToNumberOfLines: ale dokumentacja mówi, że nie powinna być wywoływana bezpośrednio (i powinna być nadpisywana). Eksperymentowałem z metodą UIView sizeToFit bez powodzenia.
Aktualizacja:I asked a new question about my problem with the NSString -sizeWithFont:forWidth:lineBreakMode: method.
+1 dla wybranego przykładowego zdania. –