章节标题不包装

时间:2012-08-26 23:52:48

标签: objective-c xcode ios5.1

我正在尝试包装我的节标题而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; 
}

1 个答案:

答案 0 :(得分: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];

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