大家好,我将一个UIImage放在了我的UITableVIew的section header中。为此,我使用了一些我在互联网上找到的代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
self.imageViewForImage.image = [helperClass resizeImage:[self.offerItem objectForKey: @"picture"] forSize:CGSizeMake(280.0, 280.0) ];
[self.imageViewForImage.layer setBorderColor: [[UIColor blackColor] CGColor]];
[self.imageViewForImage.layer setBorderWidth: 1.2];
self.imageViewForImage.contentMode = UIViewContentModeBottom;
return self.imageViewForImage;}
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 320;
return 1.0;
}
起初,图像完全按照 iPhone 的 320px 宽度进行缩放。但后来我发现,我的整个 UITableView 的 contentMode 属性设置为 "UIViewContentModeScaleToFill"。所以我添加了一行代码,告诉我的 UIImageView 不要进行缩放。在我的情况下,我将其设置为 "UIViewContentModeBottom"。
问题:这整个过程都有效,图像最终以 280x280 的纵横比显示,但我围绕图片做的边框仍然被拉伸/调整到 iPhone 的整个宽度...?!
我无法解决这个问题,因为我想要在 UIImage 周围加上边框。
感谢任何对此的帮助。
编辑:有人有什么想法吗,这里出了什么问题?