I'm scaling an image within my UIImageView using : UIViewContentModeScaleAspectFill
The image scales nicely but my issue is the ImageView sits within a UIScrollView, I've set the origin to 0,0. This is fine for the majority of images I'm using but some have a greater height and push out of bounds. I don't want to trim the image, I'd like to dynamically push the UIImageView frame down on the Y Axis based off the amount that's out of bounds.
How can I go about finding out what's out of bounds on the Y Axis / Height? Excuse the poor code example.
NSString *ImageURL = [self.detailItem objectForKey:@"job_header"];
anImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MAX_HEIGHT, 118)];
anImage.contentMode = UIViewContentModeScaleAspectFill;
[anImage setImageWithURL:[NSURL URLWithString:ImageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//Adjust the frame once the image is loaded
[self adjustPositions];
}];
Within adjustPosition:
if (anImage.image.size.height > MAX_HEIGHT) {
CGRect myFrame = anImage.frame;
myFrame.origin.y = 100;
myFrame.origin.y = anImage.frame.size.height / anImage.image.size.height;
anImage.frame = myFrame;
}
I'm also using: SDWebImage, and this is Q is relevant and may explain my issue a little bit better: UIImageView, setClipsToBounds and how my images are losing their head
Please note that I don't want to clip the bounds at all. I want to preserve bounds and simply move the origin to a true (0,0) position.