Clipping issues when picking from uiimagepicker - swift

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

Related

How can I pin an UIImageView to the top without stretching it?

I'm trying to pin an image to the top of the screen but I keep getting an extra white extra space at the top. I tried to pin the image relative to the superview instead of the save area but It didn’t work.
image's constraints relative to superview
changing the image's content mode to Scale To Fill solves the issue but it stretches the image.
After changing the image's content mode
You might want to change the contentMode of the UIImageView to either .scaleAspectFit or .scaleAspectFill, whatever fits best your needs.

keeping an image inside of the imageView using xCode and Swift

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

Set size of UIImageView

I have a very simple question,
I am working in the storyboard and is dragging a uiimageview into the viewcontroller. I configure the imageview to be square (like 100*100). I now set the image to something that has another aspect ratio (like 100*150). When I build the app I expect the imageView to be square (100*100) as i have set in the constraints, but instead it shows the imageView with the image size. So in other words, what I am asking is: How can I set the imageView to the exact size I want so it overwrites the image size? Hope this makes sense, else I can try to explain it a bit better.
Did you set imageView.clipsToBounds = true :)

How do I blur (ios7 style) a section of an image in a UITableViewCell?

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

does UIViewContentModeScaleAspectFit scale image everytime leaving transparent area around

I am having a hard time understanding how the UIViewContentModeScaleAspectFit works . I am working on app in which i want that the image should be redrawn in such a way that there must be blank area around the image and the image must be set in the center of the image view.
My main concern is that will the UIViewContentModeScaleAspectFit scale image leaving an transparent area around (in every case) or do i need to redraw image programmatically.
If the background of the UIImageView that contains that image is white, then the areas not filled by the image will be white in that view.