我有一個表視圖,我想通過使用下面的代碼在其上添加圖像,如何防止單元格圖像切割表格單元格邊框?
第一通過重寫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
?
看起來您的圖像比單元格高。嘗試增加表格行的高度。 – tarmes
@tarmes,我爲您添加了我的行高值,以查看我的圖像比行高小 – caribbean