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
Related
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.
I have been dealing with this issues for a few days now trying to figure out why images are clipping whenever I pick from the uiimagepicker. I have this button in my view controller that will take on the image that is chosen from the uiimagepicker. The image shows up but there is this weird clipping affect where it shows the entire image but there is this empty space that is black that makes the image look like it is being clipped.
The image of what the issue I am dealing with is below:
image of the current clipping issues
As now, your image view content mode is .fit that's why this is happening, For now, You need to set imageView content mode scaleAspectFill:
imageView.contentMode = UIViewContentMode.scaleAspectFill
imageView.clipsToBounds = true
I've got a UIImageView that takes up the whole cell and shows an image. I'd like to blur the bottom third of the view in the iOS7 style (we're targeting iOS7). There will be a label over the blurred part.
The issue seems to be that I can't "screenshot" the UIImageView right as I am setting up the cell in tableView:cellForRowAtIndexPath: as it hasn't loaded yet. Although i've even tried setting up a timer for a 0.1 second delay and that also doesn't work.
I've tried the stuff on http://damir.me/posts/ios7-blurring-techniques
I've tried https://github.com/justinmfischer/7blur
I'd like to use the new screenshotting API drawViewHierarchyInRect:afterScreenUpdates:
I'd also like to use apple's sample code UIImage+ImageEffects
The only thing that has worked so far has been to just put a UIToolbar in but the performance is really slow. I don't need dynamic updates.
I've managed to get the following effect a few times but it has just tinted the view and hasn't actually blurred anything so I'm a bit confused.
Use UIImageEffects sample from apple
Make a Image View with a size of the lower portion you want to blur... and then set its image to a blurred one. also set its content mode to UIViewContentModeBottom for the proper clipping
Since your image isnt the size of the cell.. first get a temp image as it is being displayed in the cell by drawing a UIImage from it.. refer for the code here
How to capture UIView to UIImage without loss of quality on retina display
then blur that image
Load this image into a UIImage, blur the image, clip to fit the area that you want. Use UIImage+blur.h
I have a CPGraphHostingView to display a graph. I changed its theme to clear color, and add a UIImageView to the CPGraphHostingView in order to add an image as the background of the graph.
But then the image will give only the mirror image like copy of the original image. So when I am taking the screenshot of that view I'm getting the mirror image copy of the original view. How to solve this?
Don't add any subviews to the CPGraphHostingView. If you must use a UIImageView, make it a sibling of the hosting view (i.e., they are both subviews of the same parent).
The easiest way to put an image behind a graph is to set the fill.
CPTImage backgroundImage = [CPTImage imageForPNGFile:pathToTheImage];
graph.fill = [CPTFill fillWithImage:backgroundImage];
You can also create the image using +imageWithCGImage: or +imageWithCGImage:scale: if you already have your background image loaded into a CGImageRef.
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