aspect-fit

UIImage aspect fit and align to top

a 夏天 提交于 2019-12-18 18:33:12
问题 It looks like aspect fit aligns the image to the bottom of the frame by default. Is there a way to override the alignment while keeping aspect fit intact? ** EDIT ** This question predates auto layout. In fact, auto layout was being revealed in WWDC 2012 the same week this question was asked 回答1: In short, you cannot do this with a UIImageView . One solution is to subclass a UIView containing an UIImageView and change its frame according to image size. For example, you can find one version

Xcode Imageview Aspect Fit Remove Extra Space

元气小坏坏 提交于 2019-12-17 20:19:30
问题 I have an imageview inside a UITableViewCell. Imageview with Aspect Fit creates a lot of extra space in the top and bottom if the image is large. The extra space (gray background color) is shown in the picture below. How do I remove the extra space? A few notes: This particular image is 890 x 589 and the screenshot was taken on a iphone 6S simulator. I am using UITableViewAutomaticDimension for automatic table cell height. There is no height constraint on the imageview so it can resize

UIButton won't go to Aspect Fit in iPhone

南楼画角 提交于 2019-12-08 22:44:25
问题 I have a couple UIButtons, and in IB they're set to Aspect Fit, but for some reason they're always stretching. Is there something else you have to set? I tried all the different view modes and none of them work, they all stretch. 回答1: I've had that problem before. I solved it by putting my image in a UIImageView , where contentMode settings actually work, and putting a transparent custom UIButton over top of that. EDIT: This answer is obsolete. See @Werner Altewischer's answer for the correct

how to set image in top avoiding space in UIimageView

青春壹個敷衍的年華 提交于 2019-12-01 04:32:39
问题 I've an UIImageView with content mode Aspect Fit of size 220x155. I'm dynamically inserting different images in different resolutions, but all larger than the size of the UIImageView. As the content mode is set to Aspect Fit, the image is scaled with respect to the ratio to fit the UIImageView. My problem is, that if for instance the image inside the UIImageView is scaled to 220x100, I would like the UIImageView to shrink from a height of 155 to 100 too to avoid space between my elements. How

UIImage aspect fit and align to top

試著忘記壹切 提交于 2019-12-01 02:39:21
It looks like aspect fit aligns the image to the bottom of the frame by default. Is there a way to override the alignment while keeping aspect fit intact? ** EDIT ** This question predates auto layout. In fact, auto layout was being revealed in WWDC 2012 the same week this question was asked Mundi In short, you cannot do this with a UIImageView . One solution is to subclass a UIView containing an UIImageView and change its frame according to image size. For example, you can find one version here . Werner Altewischer The way to do this is to modify the contentsRect of the UIImageView layer. The

Xcode Imageview Aspect Fit Remove Extra Space

佐手、 提交于 2019-11-28 12:18:44
I have an imageview inside a UITableViewCell. Imageview with Aspect Fit creates a lot of extra space in the top and bottom if the image is large. The extra space (gray background color) is shown in the picture below. How do I remove the extra space? A few notes: This particular image is 890 x 589 and the screenshot was taken on a iphone 6S simulator. I am using UITableViewAutomaticDimension for automatic table cell height. There is no height constraint on the imageview so it can resize accordingly. Thank you in advance. I had the same issue. This happens when the original image size is larger

Aspect fit programmatically in iOS?

跟風遠走 提交于 2019-11-28 10:54:38
问题 I want to insert one view into another with aspect fit option. But I can't just set contentMode for some reasons. Could you provide a solution via resizing of the inner CGRect according to the outer CGRect ? And yes, there are a lot of similar questions but no one provides such solution. 回答1: I wrote a function that should achieve what you desire. It will return the CGRect of a given innerRect , after scaling it to fit within a given outerRect , while maintaining aspect ratio. The innerRect