Adjusting UIbutton Image - objective-c

My UIbutton was stretching my images I was assigning to it with
[self.BTN_pic_1 setImage:myPIC forState:UIControlStateNormal];
I used this code to the correct resizing mode like this
[self.BTN_pic_1 setContentMode:UIViewContentModeScaleAspectFit];
The aspect fit only works once I press the button. I want the Aspect Fit to start working as soon as I load the image.
How can I get the button to do that?

Use the imageEdgeInsets to control how the image is stretched.
or
Set the contentMode of the button's imageView instead of the button's.
[self.BTN_pic_1.imageView setContentMode:UIViewContentModeScaleAspectFit];
Disclaimer:
There are many posible answers to this, you'll probably need to be more specific before we can give you a definitive answer.

It is not the button's content mode you want to fix; it's the content mode of the button's imageView. That is what is holding the image you assign when you call setImage:forState:.

Related

How to set an image to a NSButton to be resized along with the button?

I have an image (3width x 15height, the first and last pixels are rounded on the corners), and I want to create a button (the height of the button is always the same, 15px, but the width changes) that uses this image no matter what size it is, kinda like UIEdgeInsets on iOS.
I've tried to use [[button cell] setImageScaling:NSImageScaleAxesIndependently]; but the image gets distorted and loses quality.
How can I do this on OSX? Thanks!
You could probably create a custom subclass of NSButtonCell and use the Application Kit's NSDrawThreePartImage() function in the cell's drawInteriorWithFrame:inView: method.
For more info on how to use NSDrawThreePartImage(), see Cocoa Drawing Guide: Drawing Resizable Textures Using Images.
If it's possible to set this in graphical interface > Attribute Inspection > Button section Background

UIImageView overlapping effect inside a UIView

Check this URL http://krystalrae.com/
Scrolling down you will see a girl's cloths are changing on mouse wheel scrolling.
I have to create a iPad application where 3 images will appear likewise. The difference will be that in my case image change will occur horizontally rather than vertically in website. Also, i have to make it inside UIView with events touchesBegan, touchesMoved, touchesEnded and touchesCancelled
Help will be appreciated.
Thanks.
From your comment I gather that the problem is the resizing of the images in UIImageView when changing the bounds of the view.
You can set the contentMode of the image view to something else. The default is UIViewContentModeScaleToFill which is not what you want.
You could, for example, set the lower image view to UIViewContentModeBottom, and the upper image view to UIViewContentModeTop.
Don't forget to make sure your image views have sett the property maskToBounds set as YES.

UIView with button below

My question is easy with this drawing :
I have a view above the blue stroke. We can see the buttons behind because this UIView background image is transparent at the left of the button.
My problem is that buttons, behind the views are not clickable.
Is there a way to make them clickable (without playing with adding or removing the view above) ?
Thanks !
Regards,
Sébastien ;)
try to set the
[viewAboveTheBlueStroke setUserInteractionEnabled:false];
because normally the UIView steals the event handling from the other views what it covers (i.e your buttons) and it won't pass them after.
Your image link is broken.
However, you could set the buttonType of your UIBUtton to UIButtonTypeCustom
and then bring them to front:
[self.view bringSubViewToFron:myBut];
You could also consider add UIGestureRecognizers to your image in front instead.

UIButton: Image stretched when clicking

I am using EGOImageButton to handle the asynchronous download of image. I've set the contentMode to Aspect Fit using uibutton.imageView.contentMode rather than uibutton.contentMode because it doesn't work on iPhone so I used the former. The image inside the button stretched to the size of the button when I clicked on it. What is the solution to prevent it from stretched?
Pleaase help

UIButton stretching image when selected

I have a rectangle UIButton which I set the content mode to UIViewContentModeScaleAspectFit because the image is not always the same size of the button.
[btnPlaylist.imageView setContentMode:UIViewContentModeScaleAspectFit];
The thing is that when I hit the button, the image stretches like it was UIViewContentModeScaleAspectFill, ignoring that it already fits vertical or horizontal size.
What am I missing?
Did you try turning off adjustsImageWhenHighlighted? Perhaps if this property is NO it won't mess with your image.
adjustsImageWhenHighlighted A Boolean value that determines whether
the image changes when the button is highlighted.
#property(nonatomic) BOOL adjustsImageWhenHighlighted
Discussion
If YES, the image is drawn lighter when the button is highlighted. The
default value is YES.
Availability Available in iOS 2.0 and later.