我在 iOS 10 的 tableview 中显示图像时遇到问题,但相同的代码在 iOS 10 下工作,我在下面添加了我的代码片段。请帮忙。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"InboxTableViewCell";
InboxTableViewCell *cell = (InboxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[InboxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell setBackgroundColor:[cellColors objectAtIndex:indexPath.row]];
[cell.profileImageView setImage:[UIImage imageNamed:@"profile.jpg"]];
return cell;
}
在单元格中,我将图像制作成圆形
#import "InboxTableViewCell.h"
@implementation InboxTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
-(void)layoutSubviews{
self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width/2;
self.profileImageView.clipsToBounds=YES;
[super layoutSubviews];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
最佳答案
终于我得到了答案,现在我是我自己的问题。 我们只需要在 drawRect 方法中编写它就可以了。
快乐编码...
-(void)drawRect:(CGRect)rect
{
[super drawRect:rect];
self.profileImageView.layer.cornerRadius=_profileImageView.frame.size.width/2;
[_profileImageView setClipsToBounds:YES];
[_profileImageView layoutIfNeeded];
[_profileImageView setNeedsDisplay];
}
关于ios - 图像不是第一次加载到 iOS 10 的 tableview 中,而是滚动后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281936/