1

HeaderSection 内の画像と画像内のラベルを垂直方向と水平方向の中央に配置したい。しかし、私はそれをどのように作るかについて明確な考えを持っていません。私のコードは次のとおりです。

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIImage *image = [UIImage imageNamed:@"bg_title_category"];
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)] autorelease];
    UILabel *sectionTitle = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)] autorelease];

    UIImageView *sectionHeaderBG;
    sectionTitle.text = @"Trial"; //[[tableDataSource objectAtIndex: section] objectForKey: @"Title"];
    sectionTitle.textAlignment = NSTextAlignmentCenter;
    sectionTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    sectionTitle.textColor = [UIColor whiteColor];
    sectionTitle.shadowColor = [UIColor colorWithWhite:0 alpha:0.4];
    sectionTitle.shadowOffset = CGSizeMake(1, 1);
    sectionTitle.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
    sectionHeaderBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _tableView.frame.size.width/2, image.size.height)];
    sectionHeaderBG.image = [UIImage imageNamed:@"bg_title_category"];
     [headerView addSubview:sectionHeaderBG];
                [headerView addSubview:sectionTitle];
                return headerView;
}

しかし、このコードは何も中心にありません...よろしくお願いします!

4

1 に答える 1