有没有办法自定义UITableViewCell的backgroundView的大小?
我想分配一个自定义backgroundView到一个UITableViewCell。 表格是分组的。
我有点开拓者,所以,而不是使用背景视图的典型宽度,302像素,我试图使用300像素宽的图像。
这是我的代码:
- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { // a 300 pixel wide image UIImage *backgroundImage = [UIImage imageNamed:@"tableViewCellBackgroundTop"]; UIImageView *theBackgroundView = [[UIImageView alloc] initWithImage:backgroundImage]; theBackgroundView.frame = CGRectMake(10, 0, 300, 49); cell.backgroundView = theBackgroundView; }
如果我在模拟器中运行并使用xScope进行测量,则单元看起来仍然是302像素宽。 是什么赋予了? 是否有一些其他的属性,我需要设置使框架尊重我已经分配给背景视图的框架,或者是表视图单元格不打算以这种方式定制?
您可以创build一个UIView
实例,并将其设置为子视图,然后将cell.backgroundView
为创build的视图:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 49)]; [view addSubview:theBackgroundView]; cell.backgroundView = view;
- 推送通知不在iOS 10上收到,但在iOS 9和之前的版本上
- UIWebView在Safari中启动
- 用iCarousel缩放项目
- 在UIImageView上加上0.3不透明的黑色覆盖
- 在NSOperation中取消NSData initWithContentsOfURL
- UIAlertControllerbuttonfunction不起作用
- 对于viewForHeaderInSection中的自定义单元格,重新加载特定的viewForHeaderInSection IOS
- 我想触发iOS7要求用户使用蓝牙和Twitter帐户的权限
- 使用隐藏的SFSafariViewController获取Safari cookie