我有一个表格 View ,我想使用以下代码在其上添加图像,
首先通过覆盖 layoutSubviews
- (void)layoutSubviews{
[super layoutSubviews];
self.imageView.frame = CGRectMake(15, 5, 50, 45);
self.imageView.layer.cornerRadius = 5.0f;
self.imageView.layer.masksToBounds = YES;
self.imageView.contentMode = UIViewContentModeScaleAspectFill;
}
然后在 -(MyTableViewCell *)tableView:(UITableView *)tableView 中使用它
cellForRowAtIndexPath:(NSIndexPath *)indexPath
NSString *imageUrlString = [userInfoResponse[indexPath.row - beginIndex] objectForKey:@"image_url"];
NSURL * imageURL = [NSURL URLWithString:imageUrlString];
if ( [[NSUserDefaults standardUserDefaults] objectForKey:imageUrlString] == nil ) {
[[NSUserDefaults standardUserDefaults] setObject:[NSData dataWithContentsOfURL:imageURL] forKey:imageUrlString];
}
UIImage * img = [UIImage imageWithData:[[NSUserDefaults standardUserDefaults] objectForKey:imageUrlString]];
cell.imageView.image = img;
}
在这一行我添加了
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 55.0;
}
它可以很好地解决这个小问题(见附图)。我不希望单元格边框线被图像打断。
我试过玩代码,但没用。有人知道答案吗?请帮忙。谢谢
注意:它在 iOS 6 上运行良好,这个屏幕截图是在 iOS 7 上。它可以是 iOS 7 UITableView
的新设置吗?
最佳答案
转到您的 TableView Controller 并将这些代码放入 viewDidLoad:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) //should check version to prevent force closed
{
self.tableView.separatorInset = UIEdgeInsetsZero;
}
关于ios - 如何防止表格单元格边框被单元格图像切割?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19221886/