Image gets distorted when used as button image - ios

I created an image which is intended to be used as background image of UIButton. This is what I get:
The image looks great in Photoshop, but when used in iOS application as a button image it looks distorted(the lines are not strait and definitely not as smooth as in the original). How can I avoid this effect?
EDIT:// Preview window

Are you sure that aspect ratios of button and image are the same?
Another thing - use appropriate image size for button image, e.g button view is 30px high, then you need add 30px(#1x), 60px(#2x) and 90px(#3x) images. If you just add an image with 1000px it won't look good, take more disk space and reduce performance.

Related

scale type or contentMode of Image in UIButton is not working

I was trying to put an image in UIButton and the image would fill up the space keeping the aspect ratio intact. I was not able to apply the content mode. Please see the screenshot
I also tried from the code and it's not working as well
myButton.imageView?.contentMode = .scaleAspectFill
By changing the alignment, the image takes the whole space but it does not keep the aspect ratio and content mode does not work as well.
What's causing your problem is how small the image is. There are two things you can do. One option is to set the image you have now as the background image and then change the button's constraints to get the proportions right. You won't be able to have the button be the size you have it now, though, because the image will be all stretched out.
The other thing you could do is find a bigger or different image of that symbol (square.and.arrow), rather than using the one already loaded into Xcode.

how to load image from camera for specific/variable sizes?

I have a very simple requirement here but I'm looking for a solution for a while. I want to take a profile picture form the camera roll or camera and display it in two different image views (different sizes). I don't want any of these images stretched or miss any part of the image. If I use aspect to fit, top side of image is cut from smaller image view and some parts missing on the bigger image view. If I set it as scale to fit, it will get stretched!
I'm not sure how some mobile apps work. Do they save different image sizes in their server or they change the size of the image. I saw many posts how to change image size without changing aspect ratio. But I don't think it is possible to avoid stretched effects. I used some of those code to change size of image, it gets stretched all the time.
Is there any way to save the image from camera roll one time with size of 140*200 and one time 160*200? So I can use 140*200 for image views that size. But what if I have different devices and different sizes.

UIImage being stretched when copying from UIPasteboard

I have a valid image with the right content size, however I have noticed when I try to paste this image to WhatsApp or through iMessage the image get's significantly stretched. I have looked at the image and it seams to be fine on UIImageview, but somehow it gets stretched in particular to outer controls.
Is there anyway to fix this issue?
When copying an image make sure to modify the imageView's mode. There are different modes, like Aspect Fit, Scale to fill and so on.
If let's say the image is 500x300 and your imageView's size is set to 350x230 and mode to Scale to fill, it will end up stretched. Try to fiddle around and see what works for you. Most of the times i choose Aspect Fit.
Try that out.
BTW. You can find it under inspection tab in design editor or set it programmatically if you choose so.

UIButton Image size

I have 2 UIButtons. I set the background images to 2 different pngs. The pngs have different width. I looks like this:
The button size is set to the images.size.width and height.
I would like these buttons to be the same size, but when I resize the buttons manually, the images gets distorted, like this:
Is it possible to resize my buttons without distorting the image? Since it's a picture, I thought stretching doesn't make sense.
Any help would be appreciated.
Thanks!
As you guessed, you are stretching the pictures size by resizing the buttons. If I was you, I would look into manually resizing the images so that they are the same dimensions as your buttons.
Without distorting or ruining the integrity of the image the only real solution would be to add more padding to the right and left of the "delete" button.
Other options (which I personally would not reccomend) would include:
split the "Reschedule" into two lines and shrink the alarm clock, so it would read:
Re-
Schedule
Enlarge the trashcan icon manually (this will even them out a little more)
Manually shrink the size of the reschedule icon (your legibility will suffer)
Regardless of the route you take I would resize or edit the original files in a program such as Photoshop or Fireworks to preserve the integrity of the UI elements. Be sure to scale proportionally in those programs to avoid more distortion and stretching.

How do you fit a large png image into a smaller custom Round Rect Button on XCode without losing image quality?

I am creating a button for my application that, when pressed shows an indention looking effect to make it appear that the user is clicking a real button. It is very simple, using only an image for the default state and the depressed one for the highlighted state. I'm having a few problems. The quality is terrible. I have uploaded the images to XCode in the exact pixels they will be presented in my application but when I export it from Illustrator it gets really pixelated. So I was wondering if there was a way for me to upload an image a few times bigger than my button and have it shrink to fit the button size. I've tried to do that but when I run my app it gets really messed up and weird looking. I would just put text inside the button but then it ruins the pressed effect. Any ideas?
If you export an image at the same aspect ratio as the button, the image will be re-scaled to fit within your button. Don't forget to use the Custom style so you don't get the button oval.
However generating an exact pixel version of your button should be possible, and look good - especially if you specify a 2x sized #2x version of the image for retina use. Are you sure your Illustrator export settings are correct? One thing to consider is that perhaps anti-aliasing needs to be enabled on export.
This page has a helpful quick checklist for how to save for the iPhone from Illustrator (Scroll down to the "How To Save Art For The iPhone In Illustrator" header)
http://www.vickiwenderlich.com/2011/11/faq-how-do-i-save-art-for-the-iphoneipad/

Resources