請看看我的代碼,我的標籤不換行。在指數連續的UITableViewCell不換行文本
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyCellIdentifier = @"MyCellIdentifier";
UITableViewCell *cell = (UITableViewCell*)[self.tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyCellIdentifier] autorelease];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setClipsToBounds:NO];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UILabel *label = [[UILabel alloc] init];
[label setBackgroundColor:[UIColor clearColor]];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setNumberOfLines:0];
[label setTextColor:[UIColor darkGrayColor]];
[label setShadowColor:[UIColor whiteColor]];
[label setShadowOffset:CGSizeMake(0, 1)];
[[cell contentView] addSubview:label];
[label release];
}
UILabel *froglabel = (UILabel *)cell;
NSUInteger row = [indexPath row];
CGSize textSize;
CGSize labelSize = { 100, 20000 };
[froglabel setText:genus];
[froglabel setFont:detailFont];
[froglabel setTextColor:[UIColor whiteColor]];
textSize = [[froglabel text] sizeWithFont:[self detailFont] constrainedToSize:labelSize lineBreakMode:UILineBreakModeWordWrap];
表視圖高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
CGSize textSize;
CGSize labelSize = { 300, 20000 }; // width and height of text area
textSize = [[self genus] sizeWithFont:[self detailFont] constrainedToSize:labelSize lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"%i = height %f", row, textSize.height);
return textSize.height + 7;
break;
試了一下,還是一樣沒有使用setNumberOfLines工作 – Desmond
:0是正確的設置這告訴,因爲它需要自動換行的標籤,使用盡可能多的行。將其設置爲2將只允許兩行文本然後......就會出現。 – Openside