Increasing size of image in UIButton - ios

Currently, I have a UIButton and want to set an image inside of it. I'm successfully able to set the image to inside the UIButton but for some reason, the image is VERY small compared to the UIButton. I want to increase the size of the image - no, not cover the entire button just a slight increase so it's a bit more visible on the UI.
More information, my UIButton is 40x40. The answers I've seen on StackOverFlow have indicated changing the Content Mode but even those answers have not helped. I'm a little stuck at this point so any expertise/advice would be highly appreciated!

Figured it out. I had to use image insets. This property allows to reposition the drawing rectangle for the button image. By setting values to the top, bottom, left, and right image insets we're creating a rectangle and thus, increasing the space for our image to be draw in.
I had actually seen this suggestion in other answers and had tried it but on IB, nothing seemed to change but I finally decided to test it on simulator and saw the affects.

Related

UIbutton stretch when clicked unexpectively

I am trying to modify a frame work and have encountered the following problem.
I have replaced one of the button image in the framework's xib file with my own one. The image itself is approximately 20Wx20H but I have set the button size to be 40Wx40H so that the clickable area is larger than the actual image.
When the VC is displayed, I see the image to be normal 20x20 aspect ratio. However, when I clicked on the button, it stretches to 40x20 and goes back to default upon release. I was wondering if there is a UIButton parameter that I can disable which was enabled by the framework somewhere? I have done a search on the buttons in the code and could not find anything relating to stretching the button. So I am guessing somewhere in IB there is my solution?
Below are the images for the button when touch down or not touched down.
Have you tried the following?
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
Also are you using autolayout? If yes, what are the constraints?

Resize UIImageView with autolayout

I've got a view with a UIButton in it. I've got some animations that, among others, scale the button down.
The problem is that the button is actually scaling well following the constraints when it only has text, but when I set an image either as its image or its backgroundImage, the button is not scaling anymore.
I've tried playing with contentModes of both the UIButton and its inner imageView with no results (I've tried, literally, all the possible answers of this, this, this and this stackoverflow questions).
Any hint? Thank you all in advance
UPDATE
I've noticed that the issue is with UIImageViews, not UIButtons (the problem with the button was due to the imageView inside it).
I think your UIButton does resize, but the ImageView inside does not. The ImageView of the UIButton is always displaying normal image size.
The only possibility I found is to put another UIImageView below the Button with constraints top/bottom/left/right to the Button. This one can be perfectly adjusted.
I use subclassed buttons for that with their own ImageView inside. There you need to be careful to put userInteractionEnabled = false on the ImageView.
Finally I've got it.
In both cases (UIButton and UIImageView), you have to adjust Content Compression Resistance Priority to let the view to scale down. In my case, setting it to 749 was enough.

Text over image in Uiview

sorry, if this might been asked before.
I am laying out a viewcontroller for a new app. It will include a photo (UIImageview) which fills the nearly all of the screen and it should include a scrollable UITextview which should fill the bottom right corner of the screen and including a description of the photo.
So i have two views over one space and i would like to give the Textview priority over the UIimage. Is there any other way then reducing "Alpha" of the UIImage to make the Textview visible ? Tinkered around with Conten Hugging Priority and Content Compression ... to no avail.
Any help would be appreciated
Thanks
The easiest way to make sure text is easily readable over any image, I suggest setting a background of color rgba(.2, .2, .2, .8) or something similar and then using a white font color.
Thanks everybody for trying to help me out... I have found the solution... It is perfectly ok to overlay Views in Interfacebuilder but then it is imperative to use a background color for the overlaying textview with reduced opacity.

How to avoid distort and stretch image in Custom UIButton while using vector image set?

Below is my storyboard, I had quite a lot of constrains to make those four buttons fit into the screen nicely. However, after I put the images into the buttons and check the storyboard preview, all images are distorted. I try to adjust (had tried all of the options) the view mode at attribute inspector panel but seems no effect at all.
One more thing, I am using PDF as vector type image set, not regular .png file I am wonder if that matters? Should I change the way vector image displayed inside UIButton programaticly?
The verctor image size was 500px*500px. I resize the image into 50px*50px after #orkenstein 's reminader, xcode may not be able to handle oversized vector image that well. The image appear inside button as it is exactly 50px*50px and lost its ability to scale. Also as he sugested I should but the vector image inside an UIImageView and after my test, it works perfectly fine in an UIImageView.
Setting the contentMode on the button itself doesn't work for me, but setting it on the button's imageView does. From this Stackoverflow answer:
button.imageView?.contentMode = .scaleAspectFit

FBProfilePictureView not filling the assigned space in the storyboard

Well pretty straight forward.
FBProfilePictureView uses (by my knowing) all the UIImageView methods. Knowing this i tried to use AscpectToFit (first in the storyboard second in the code when the first one didn't work.
the i tried this:
self.fb_background.contentMode = UIViewContentMode.ScaleToFill
This works only in height. I also tried resizing the frame this resulted in my images halfway down my page(instead of the top left
what am i doing wrong?
The problem is that my pictures width is not correct! its
The problem is that FBProfilePictureView contains a UIImageView and does not expose it for you to modify it's properties.
It downloads a square image if pictureCropping == FBProfilePictureCroppingSquare otherwise it downloads a small, medium or large image depending on the width of the frame. But there is no way to control how this image is scaled to fill the FBProfilePictureView.
I created a replacement view which exposes the UIImageView through a read-only imageView property and therefore allows you to control its contentMode.

Resources