UIImageView resizes automatically

前端 未结 2 1205
猫巷女王i
猫巷女王i 2020-12-18 11:22

I am trying to set an image to a UIImageView of a SimpleTableCell in a UITableView. I have changed the size of the imageview, but when

相关标签:
2条回答
  • 2020-12-18 11:50

    When weird resizing behavior happens for me, Autolayout is my first suspect. Try turning Autolayout off and see if the resizing still occurs.

    1. Select the ViewController in the Storyboard or NIB
    2. Click the 'File Inspector' tab on the right hand side of your Xcode window
    3. Under the 'Interface Builder Document' section, uncheck 'Use Autolayout'

    If you need Autolayout you'll probably have to battle it with some code.

    0 讨论(0)
  • 2020-12-18 11:51

    Your SimpleTableCell is a subClass of UITableViewCell that you created? This imageView is a property of this subclass?

    Just a guess:

    Every UITableViewCell has a built-in imageView read-only property. In the code that you posted, you are using this default property, which I believe cannot have it's frame modified, it's kind of fixed in the left side of the cell.

    Look for imageView property inside the documentation: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/index.html#//apple_ref/occ/instp/UITableViewCell/imageView

    So, if you do have your custom cell with your own imageView, make sure to not call it imageView too, because you may end using the default UITableViewCell's property, and not your own, which will have all your frame customizations and etc.

    You should reference your cell by your customClass and call your property like this:

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        UIImage *userImage = [UIImage imageWithData:userImageData scale:self.profileImage.frame.size.height/self.profileImage.frame.size.width];
    
        SimpleTableCell *cell = (SimpleTableCell*)[self.myTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    
        cell.myImageView.image = userImage;
    }
    

    Don't know if the problem is really related do this, so let me know if it helped or not.

    0 讨论(0)
提交回复
热议问题