Fer*_*ndo 1 iphone cocoa-touch uikit
我想在UITableViewCells之间保持透明.细胞之间的空间.
我用户自定义创建的单元格和设置背景我使用此代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCell = @"CustomBookingCell";
currentBooking = [arrayBookings objectAtIndex:indexPath.row];
CustomBookingCell *cell = (CustomBookingCell *)[tableView dequeueReusableCellWithIdentifier:CustomCell];
if (cell == nil) {
UIViewController *c = [[UIViewController alloc] initWithNibName:@"CustomBookingCell" bundle:nil];
cell = (CustomBookingCell *)c.view;
[ c release ];
}
bookingImage = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:currentBooking.imageSource]];
[cell.imageForBooking addSubview:bookingImage];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.contentView.backgroundColor = [UIColor clearColor];
UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
UIImage* bgImage = [UIImage imageNamed:@"Background_300_82.png"];
UIColor *bgColor = [[UIColor alloc] initWithPatternImage: bgImage];
backgroundView.backgroundColor = bgColor;
cell.backgroundView = backgroundView;
cell.label.text = currentBooking.title;
[bookingImage release];
[bgColor release];
[backgroundView release];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 90;
}
Run Code Online (Sandbox Code Playgroud)
单元格的高度比tableCellBg.png高10个像素.我的背景视图也有一个图像作为背景(当然,这个背景应该在单元格之间显示).
所以我尝试在底部的tableCellBg.png中添加10个带透明度的像素来解决这个问题.但是细胞之间的空间是黑色的.我无法看到我的单元格之间的视图背景.
我该怎么办?我是否必须使用tableCellBg.png的高度在cellForRowAtIndexPath中创建一个UIView,然后将Custom UITableViewCell作为子视图添加到创建的UIView中,其高度更低?
或者有更简单的方法来实现这一目标吗?
您的表格视图需要清晰的背景颜色.例如
myTableView.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)