Reputation: 621
I have UIImageView
with contentMode = UIViewContentModeScaleAspectFit
I need this mode to display my image properly. But also I need imageView cropping image when its frame changes like it was with UIViewContentModeTopLeft
.
How I can obtain this?
Edited:
imageView.contentMode = UIViewContentModeTopLeft;
imageView.image = someImage;
Now I get this (and it's ok, image scaled properly and looks good):
Then, I have method:
- (void)setRating:(double)rating {
double starWidth = imageView.image.size.width / _maxRating;
CGRect oldFrame = self.frame;
imageView.frame = CGRectMake(0, 0, rating * starWidth, oldFrame.size.height);
_rating = rating;
}
after this method I need to get something like that:
BUT because of UIViewContentModeScaleAspectFit
I get scaled image
Upvotes: 0
Views: 3148
Reputation: 902
You can't really get what you want from that imageView in the method you are attempting without a lot of extra work. When you resize the view you will see that scaling, that is the mode you set and thats really all that will happen. There are a number of possibilities, many involve resizing things yourself thru subclassing. But as for solutions:
Upvotes: 1