当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - iOS 7 UItableview cell background view

问题描述:

I am using a image view as tableview cell background view. When I am compiling my source in xcode 4.x, it works fine i.e, In both iOS 6.x and 7.0 it is working fine. But when I compile my source in xcode 5.0, the background image view is not appearing iOS 7.

Any idea, why it is not working? is there any restrictions on uitableview cell background view in iOS 7?

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell];

UIImageView *cellBgView =[[UIImageView alloc]init];

[cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]];

[cell setBackgroundView:cellBgView];

}

网友答案:

try adding : cell.backgroundColor = [UIColor clearColor];

网友答案:

You must set the background in willDisplayCell. The below code is same as yours only thing is that move it in willDisplay method

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if(cell.backgroundView==nil){
        UIImageView *cellBgView =[[UIImageView alloc]init];
        [cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]];
        [cell setBackgroundView:cellBgView];
    }
}
网友答案:

Try this. It's work for me

 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell];
UIView *cellBgView =[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [cell frame].size.width, [cell frame].size.height)];
[cellBgView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBgView.png"]]];
[cell setBackgroundView:cellBgView];
网友答案:

The only thing missing is setting frame to cellBgView. Setting image to it will not resize imageView. However if you initialize imageView with initWithImage: , it will resize imageView to fit the image.

网友答案:

You just need to apply autosizing in your imageview.

If your imageview is applied to an entire screen. Assign all margins to it.

Checkout the image

分享给朋友:
您可能感兴趣的文章:
随机阅读: