UITableViewCell imageView padding

后端 未结 4 598
-上瘾入骨i
-上瘾入骨i 2021-01-12 07:22

I would like to set up margins or paddings for UITableView cells imageView, how could I do that? With heightForRowAtIndexPath I can only set rows height. And it

相关标签:
4条回答
  • 2021-01-12 07:28

    This works on iOS 7:

    - (void)layoutSubviews
    {
        [super layoutSubviews];
        CGRect imageViewFrame = self.imageView.frame;
        imageViewFrame.origin.x = 10;
        imageViewFrame.origin.y += 5;
        imageViewFrame.size.height -= 10;
        imageViewFrame.size.width -= 10;
        self.imageView.frame = imageViewFrame;
    }
    
    0 讨论(0)
  • 2021-01-12 07:31

    Without subclassing:

    cell.imageView.transform = CGAffineTransformScale(CGAffineTransformIdentity, .5, .5);
    

    change the '.5' with the right proportion for your case

    0 讨论(0)
  • 2021-01-12 07:32

    updated for swift3

    cell?.imageView?.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
    
    0 讨论(0)
  • 2021-01-12 07:41

    The best solution here is to create your own cell, add image, labels inside of contentView and tweak them how you want.

    But there's also another way, again you need to create a subclass from UITableViewCell and override layoutSubviews selector:

    - (void)layoutSubviews
    {
        [super layoutSubviews];
        self.imageView.frame = CGRectMake(10, 10, 50, 50);
        self.imageView.contentMode = UIViewContentModeCenter;
    }
    
    0 讨论(0)
提交回复
热议问题