Reputation: 5
How can I add one image on several cells of UITableView
?
I add an image to one top cell, like this:
But after scroll to bottom and top I see this:
Second and third cell has a z-index more that first cell.
How I can do this?
Thanks..
Upvotes: 0
Views: 319
Reputation: 3869
Use addSubview on tableview directly.
let imageView = UIImageView(frame: CGRectMake(0, 0, width, height))
imageView.image = UIImage(named: "My Image")
self.tableView.addSubview(imageView)
Upvotes: 0
Reputation: 8255
You wouldn't add it to a single cell, but to the tableview itself. Then - in a tableview subclass - you would make sure that in the layoutSubviews the image view stays on top and the position gets adjusted to stay in a fixed place. Or next to a specific cell if you want that.
Upvotes: 0
Reputation: 5
I did it.
img1
) object to UITableView (table1
)img1.Layer.ZPosition
to 1 that the image was above cells in the table1
img1.Layer.ZPosition
to 2 that a header was above an imageThanks all for help!
Upvotes: 0
Reputation: 5268
You can add image as subview to table
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[UITableview addSubview:imv];
or
you can increase the height of cell
Upvotes: 0
Reputation: 134
if you want to add the image on the tableView, get the scroll view instance from the tableview using tableviewobj.scrollview and then add the image as subview on the scrollview and make the image come front using bringsubviewtofront method.
Upvotes: 0
Reputation: 1652
If you want to add image on cell then I would recommend you to make custom cell with imageView .
Upvotes: 0
Reputation: 3970
Are you adding the image to the CellView or to the TableView?
You can try the following function in which you have to specify the filename, position of the picture, size and view to which you want to add it.
- (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];
}
Upvotes: 1
Reputation: 5081
UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 20, 25)];
imgView.image=[UIImage imageNamed:@"img.png"];
[cell addSubview:imv];
neither you can directly add image to cell
-(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;
}
try this code....
and adjust the image size....
Upvotes: 1