0

我正在尝试包装我的部分标题并且UILineBreakModeWordWrap没有帮助。知道我做错了什么吗?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{ 
    UIView *rOView = [[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] ;   
    UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    sectionLabel.backgroundColor = [UIColor clearColor];
    sectionLabel.font = [UIFont boldSystemFontOfSize:18];
    sectionLabel.frame = CGRectMake(70,18,200,20);
    sectionLabel.text =  @"A really really long text A really really long text A really really long text";
    sectionLabel.textColor = [UIColor blueColor];
    sectionLabel.numberOfLines = 0;
    sectionLabel.lineBreakMode = UILineBreakModeWordWrap;

    [roView addSubview:sectionLabel];
    return roView; 
}
4

1 回答 1

0

你没有给标签一个有意义的框架——只有 CGRectZero。设置标签后,调用-sizeToFit它,如下所示:

UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
sectionLabel.backgroundColor = [UIColor clearColor];
sectionLabel.font = [UIFont boldSystemFontOfSize:18];
sectionLabel.frame = CGRectMake(70,18,200,20);
sectionLabel.text =  @"A really really long text A really really long text A really really long text";
sectionLabel.textColor = [UIColor blueColor];
sectionLabel.numberOfLines = 0;
sectionLabel.lineBreakMode = UILineBreakModeWordWrap;
[sectionLabel sizeToFit];

编辑:我现在看到您确实设置了标签框架。但是高度太短,无法显示所有文本。

于 2012-08-27T01:30:26.640 回答