UITableVIewcell中图片不能改变大小的原因

你有没没有发现,有时候把图片放进cell.imageView中时无法顺利改变大小呢?

其实根本原因是要在layoutSubviews重新配置一下,cell的布局里面默认有一个imageiView,同时,我们如果自己定义的话也需要在layoutSubviews中布局控件。

 

- (void)layoutSubviews {

    //改变系统cell.imageView大小的方法

    [super layoutSubviews];

    

    self.imageView.bounds =CGRectMake(10,5,30,30);

    

    self.imageView.frame =CGRectMake(10,5,30,30);

    

    self.imageView.contentMode =UIViewContentModeScaleAspectFit;

    

    

    //cell.textLabel

    CGRect tmpFrame = self.textLabel.frame;

    

    tmpFrame.origin.x = 46;

    

    self.textLabel.frame = tmpFrame;

 

    //cell.detailTextLabel

    tmpFrame = self.detailTextLabel.frame;

    

    tmpFrame.origin.x = 46;

    

    self.detailTextLabel.frame = tmpFrame;

    

}

posted on 2015-12-25 23:48  十一点前要睡觉的小寒  阅读(259)  评论(0编辑  收藏  举报