[英]iOS 7 UItableview cell background view
我使用圖像視圖作為tableview單元格背景視圖。 當我在xcode 4.x中編譯我的源代碼時,它工作正常,即,在iOS 6.x和7.0中,它工作正常。 但是當我在xcode 5.0中編譯我的源代碼時,背景圖像視圖沒有出現在iOS 7中。
任何想法,為什么它不起作用? 在iOS 7中對uitableview單元格背景視圖有任何限制嗎?
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:accountProfileTypeCell];
UIImageView *cellBgView =[[UIImageView alloc]init];
[cellBgView setImage:[UIImage imageNamed:@"cellBgView.png"]];
[cell setBackgroundView:cellBgView];
}
嘗試添加:cell.backgroundColor = [UIColor clearColor];
您必須在willDisplayCell中設置背景。 下面的代碼與你的相同,只是在willDisplay方法中移動它
-(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];
}
}
嘗試這個。 這對我有用
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];
唯一缺少的是將幀設置為cellBgView。 將圖像設置為不會調整imageView的大小。 但是,如果使用initWithImage:初始化imageView,它將調整imageView的大小以適合圖像。
您只需在imageview中應用自動調整大小。
如果您的imageview應用於整個屏幕。 為其分配所有邊距。
檢查圖像
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.