0

の複数のセルに1 つの画像を追加するにはどうすればよいUITableViewですか?

次のように、1 つの上部セルに画像を追加します。

スクリーンショット

しかし、上下にスクロールすると、次のように表示されます。

スクリーンショット

2 番目と 3 番目のセルは、最初のセルよりも大きい z インデックスを持っています。

どうすればこれを行うことができますか?

ありがとう..

4

9 に答える 9

1

画像をCellViewまたはTableViewに追加していますか?

ファイル名、画像の位置、サイズ、および追加するビューを指定する必要がある次の機能を試すことができます。

- (void)createImage:(NSString *)name
                   inX:(NSInteger)x
                   inY:(NSInteger)y
                 width:(NSInteger)w
                height:(NSInteger)h
                  view:(UIView *)v{

    UIImage *background = [UIImage imageNamed:name];
    CGRect rect = CGRectMake(x, y, w, h);
    UIImageView *yourImageView = [[UIImageView alloc] initWithFrame:rect];
    yourImageView.image = background;
    [v addSubview:yourImageView];
}
于 2013-08-19T12:03:38.523 に答える
1
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[cell addSubview:imv];

画像をセルに直接追加することもできません

 -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{    
   static NSString* CellIdentifier = @"Cell";

   UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil)
      cell = [[[UITableViewCell alloc] UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

   cell.textLabel.text = @"I'm a UITableViewCell!";
   cell.imageView.image = [UIImage imageNamed:@"image.png"];

   return cell;
}

このコードを試してください....

画像サイズを調整します....

于 2013-08-19T11:59:16.993 に答える
0

tableview で addSubview を直接使用します。

let imageView = UIImageView(frame: CGRectMake(0, 0, width, height))
imageView.image = UIImage(named: "My Image")
self.tableView.addSubview(imageView)
于 2016-04-12T08:31:18.190 に答える
0

セルに画像を追加したい場合は、 imageView でカスタムセルを作成することをお勧めします。

于 2013-08-19T12:14:42.413 に答える
0

画像をサブビューとしてテーブルに追加できます

UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[UITableview addSubview:imv];

また

セルの高さを増やすことができます

于 2013-08-19T13:03:01.213 に答える
0

セルの高さを画像サイズとして調整します。

于 2013-08-19T12:00:00.083 に答える
0

単一のセルに追加するのではなく、テーブルビュー自体に追加します。次に、tableview サブクラスでは、layoutSubviews で画像ビューが一番上にあり、位置が固定された場所に留まるように調整されていることを確認します。または、必要に応じて特定のセルの横に。

于 2013-08-20T20:59:01.403 に答える