3

このチュートリアルに従って、カスタムの「パルス スタイル」UITableView に取り組んでおり、すべてが順調に進んでいます。いくつかの変更と拡張を行いましたが、実装したい機能が 1 つあります。それは、水平方向のバウンス領域の色です。

これは、テーブル ビューを含むセルを作成する方法です。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
    NSString *cellIdentifier = [@"TableViewCell" stringByAppendingFormat:@"%i", self.content.indexInArrayOfViews];
    UIView *view = [self.content viewAtIndex:indexPath.row];
    UITableViewCell *cell = [self.horizontalTableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] autorelease];

        view.center = CGPointMake(view.center.y,view.center.x);
        view.contentMode = UIViewContentModeCenter;

        view.transform = CGAffineTransformMakeRotation(M_PI_2);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    [cell addSubview:view];

    return cell;
}

セルの再利用の問題があることは承知していますが、今のところ、この色を変更したいと思います [IMG] .

垂直方向のテーブル ビューのバウンス領域の色を制御できますが、水平方向のビューでこの成功を再現するのに苦労しています。

これは私が垂直に行う方法です:

CGRect frame = self.tableView.bounds;
    frame.origin.y = -frame.size.height;
    UIView* topBack = [[UIView alloc] initWithFrame:frame];
    topBack.backgroundColor = [self.delegate backgroundColorForTopOfTableView];
    [self.tableView addSubview:topBack];
    [topBack release];

これは、この StackOverflow の質問によるものでした。

水平テーブル ビュー (テーブル ビュー セルにネストされている) の色/背景を変更するにはどうすればよいですか?

これは、関連する iPhone のスクリーンショットと IB のスクリーンショットを含むアルバムです。

4

1 に答える 1

0

私は解決策を発見しました:

if (indexPath.row == 0){
    UIView *bounce = [[UIView alloc] initWithFrame:CGRectMake(-320, 0, 320, 150)];
    bounce.backgroundColor = [self.delegate colorForBounceRegionAtRow:self.content.indexInArrayOfViews];
    [view addSubview:bounce];
}

if (indexPath.row + 1 == self.content.viewCount){
    UIView *bounce = [[UIView alloc] initWithFrame:CGRectMake([self.content widthOfViewAtIndex:self.content.viewCount - 1], 0, 320*2, [self.content greatestHeight])];
    bounce.backgroundColor = [self.delegate colorForBounceRegionAtRow:self.content.indexInArrayOfViews];
    [view addSubview:bounce];
}

これにより、画面全体に相当する色付きの四角形が最初と最後の要素に追加され、バウンス領域のような錯覚が生じます。

于 2012-08-12T12:59:03.870 に答える