I am new to iphone development. I want to display the actual size of the image in image view. I have created image view by using Interface builder and set the properties. Now the problem is, I have set into "Scale to Fill", then the image will be stretched in the full screen. Now i want to display the actual size of the image will be displayed in image view. For example 52X52 size image should be displayed with the same size in the image view.The 1200X1020 size image should be fit to the size of the image view .So according the size of the image it should fit to image view and i want the image smaller than image view should retain its original size(It should not stretch to fit the image view).
Is it any possible solution to achieve it, please guide me.
Thanks.
You're going to have to check the dimensions on the UIImage yourself and then set the proper property on the UIImageView: myImage.contentMode = UIViewContentModeCenter , etc
The different content modes: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/c/econst/UIViewContentModeScaleToFill
Related
I'm trying to create a very simple app where I have an Image View window that I want to keep at 300x300 pixels. Then I have buttons below that depending on which button you click will change the image inside of the image view to a logo I have stored in the Assets folder. I just grabbed the logos off the internet so they are all differing sizes.
I created the image view, set its size to 300x300 and then using the image attribute selected the image I want shown when the app is loaded. In the storyboard, the image is shown just how I want it inside the image view, however, when I build and run the app, the image blows out of the image view box and returns to its original size.
I have setting the content mode on my image view, view attribute to scale to fill as well as aspect fit and neither work when the app runs.
My methods to change the image in the image view are very simple and are just
#IBAction func changeImage(_ sender: UIButton) {
imageView.image = UIImage(named: "name of my image in the assets folder")
}
What do I need to do to keep the images in my assets folder inside of the image view box and keep that image view box set at a sized of 300x300. If you can't tell, this is my first time using xCode and swift. I feel like there has to be a simple solution I can't figure out.
I just ended up using a free resizing tool on the internet to resize all of my images to 300x300. I'm sure there's a way to make it work programmatically but I couldn't figure it out.
You can make your imageView 300x300 fixed size from the constraints :
1- choose the imageView
2- add constrains
3- set your width & height
Then you will choose Top, Trailing & leading constraint
It's preferable to make the image content mode = scaleToFill
My application is downloading image files from the api network call, and loading them directly into the tableviewcell uiimageview. Some of those images are smaller and some are bigger in size. I would like to know how to resize an image of any size to our desired uiimageview size in our tableview cell. Please help me with this.
I tried my UIImageview's content modes both "aspectfit" & "aspect-fill" still the images are not sizing to the desired uiimageview size.
In collection view, I have changed content mode from storyboard in Xcode but image not in .
I am using a collection view in a view controller and in UIImage view I can't replace the aspect fill with aspect fit .
Try the following:
make sure all constraints are marked correct according to the cell.
in the Xcode inspector mark image content mode as aspect fit.
give image a height.
My application have an function that allow user to move and scale the image just like setting allowsEditing = YES with UIImagePickerController.
My approach is having a scrollview which allow user to zoom with level 1-4
There is only a image view on the scrollview.
At the end, I want to crop the image as the screen size. How can I do it?
The trick is to capture the layer of the view containing the scaled / rotated image. In this case you need to capture the scrollview layer NOT the image itself.
I have a UIImage capture category for this...check out my article and download the source code.
UPDATE: to crop part of the image as per the comment below...
First capture the whole view then crop the image to the specified rect using the following method in the UIImage+Resize category (also in the article...)
- (UIImage *)croppedImage:(CGRect)bounds;
I am using a TTTableSubtitleItem with UITableViewStyleGrouped. When viewing the tableView, the image that is in the TTTableSubtitleItem gets skewed to fit the image view (rather than just placing image without changing dimensions) and also the image does not get a rounded edge when it is the first item in the section.
Does anyone know of a way to fix these two issues?
I needed to subclass TTTableSubtitleItem and draw my own images.