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.
Related
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:.
I need to display NSImageView on resizable NSWindow. The image displayed in the view should scale down if it's too big to fit image view in the widnow and it should also change its size when resizing the window. I am able to achieve correct behavior using Auto-Layout, and setting imageScaling property of NSImageView to NSImageScaleProportionallyDown. Unfortunately it's not working when my image view's imageFrameStyle property is set to NSImageFrameNone (it works for any other option like NSImageFramePhoto or NSImageFrameGrayBezel). I don't want any frame to be displayed, like with NSImageFrameNone, but disabling the frame breaks autoresizing - it looks like with frame set to NSImageFrameNone image is not scaled down and NSImageView is scaled up to match displayed image size. Anyone have solution for that issue?
It occurs that it's easier than I thought. The problem was with Auto-Layout, not with NSImageView scaling logic. Using InterfaceBuilder with my image view selected I had to change "Content Compression Resistance Priority" to lower value (it's located on Size Inspector tab in Xcode5). That solved my problem and the image is now scaled properly when resizing window.
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
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.
I dragged A round rect button into the nib and set a background image for the button. However, the image didn't fill up the whole space, it left out a narrow border on the sides of the button. How do I get rid of this border? Thanks.
if you want to use a custom background image for the UIButton, you should change the button type to UIButtonTypeCustom instead of UIButtonTypeRoundedRect.
(you can do this in the Interface Builder as well)