UITableView
のようなセクションの背景画像を設定できますかUITableViewCell
backGroundView
。私の調査によると、それは不可能であり、行のようなセクションをカスタマイズする必要があります。
これとは別に、より良い解決策を得ることができます。
前もって感謝します!
UITableView
のようなセクションの背景画像を設定できますかUITableViewCell
backGroundView
。私の調査によると、それは不可能であり、行のようなセクションをカスタマイズする必要があります。
これとは別に、より良い解決策を得ることができます。
前もって感謝します!
誰かがまだ興味を持っている場合は、実際にはかなり簡単な解決策があります。UITableView は、セレクター rectForSection を使用して、各セクションのフレームを通知します。
各セクションに背景画像を追加すると、次のようになります (View Controller のどこかに):
for(int i = 0;i < [self numberOfSectionsInTableView:self.tableView]; i++) {
UIImage *img = [[UIImage imageNamed:@"background"] resizableImageWithCapInsets:UIEdgeInsetsMake(30.0, 30.0, 40.0, 40.0) ]; //In this example the image is stretchable
UIView *borderView = [[UIImageView alloc] initWithImage:img];
CGRect section_rect = [self.tableView rectForSection:i];
borderView.frame = section_rect;
[self.tableView addSubview:borderView];
}
テーブルビューにデータをリロードすると、これもやり直す必要があることに注意してください。
はい、私は次の方法でこれを行っています、私はそれがあなたにもうまくいくと思います、....
-(void)addBackgroundViewForSectionIndex:(int)tagIndex {
for (UIView * subview in tableView.subviews) {
if(subview.tag == tagIndex)
[subview removeFromSuperview];
}
CGRect sectionFrame = [tableView rectForSection:tagIndex];
UIImageView *newView = [[UIImageView alloc]initWithFrame:sectionFrame];
newView.tag = tagIndex;
[newView setImage:[UIImage imageNamed:@"image.PNG"]];
[tableView addSubview:newView];
[tableView sendSubviewToBack:newView];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [collection objectAtIndex:indexPath.row];
[self addBackgroundViewForSectionIndex:indexPath.section];
return cell;
}
問題があれば教えてください...:)
いいえ、UITableView
意図したとおりに使用することはできません。他の人が示唆しているように、セクション ヘッダーは、ヘッダーが表示されている間だけ表示されるため、機能しません。上にスクロール中に消えるとすぐに、背景画像が消えます。
あなたの2つのオプションは次のとおりです。
UIImageView
インスタンスをサブビューとしてテーブル ビューに直接追加します。手動でサイズを調整して配置する必要があるため、楽しくありません。これはちょっと難しいことです。UICollectionView
します (まさにあなたが探しているものです)。このUICollectionView
方法の方がおそらく優れていますが、正直なところ、どちらのオプションも多くの作業を必要とします。
TableViewのセクションの背景を設定できます。
以下のようにデリゲートメソッドを見てください:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImageView *bgImgView = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0,0.0,tableView.bounds.size.width,40.0)] autorelease];
bgImgView.image = [UIImage imageNamed:@"yourimage.jpg"];
return bgImgView;
}
これがお役に立てば幸いです。
乾杯!
table= [[UITableView alloc] initWithFrame:CGRectMake(7,0, 307, 124) style:UITableViewStylePlain];
[table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tablebg_pt12.png"]];
imageView.frame=CGRectMake(0, 0, 307, 124);
imageView.image= [UIImage imageNamed:@"tablebg_pt12.png" ];
table.backgroundView = imageView;
[imageView release];
table.delegate = self;
table.dataSource = self;
// table.backgroundColor=[UIColor clearColor];
[viewTable addSubview:table];