I am trying to set a image for a UIButton.
I don't know the difference between the setBackgroundImage:Forstate and setImage:Forstate:
Could anyone help me out?
Thanks and best regards.
setImage:forState: sets the image as the actual content of the button. For example, you can not see the button title even though you set it, because you have set an image as the content.
setBackgroundImage:forState: sets the image as the background. In this case, you can set the title and it is displayed on top of the image.
setBackgroundImage: follows the frame, i.e. if u change the frame, the background image is streched or shrinked with it. Contrary on the setImage, its not the same. The image takes its own size. In setImage the image is the actual content of the button.
The difference is in the framing
I will explain you with the help of example suppose your image size is 40*40 and button frame is 20*20 then if you use setBackgroundImage:forState: method the image will be displayed in 20*20 frame and if you use setImage:forState: method you will see a button with image size of 40*40 frame.
This is the difference.
Happy Coding!!
Related
How can i edit the background of an image (not imageview) and set it to be transparent. I had search a lot but can find nothing. Any help?
Do you mean you want to do image processing using swift?
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
I have a UIButton in which I want to insert an image that would stretch to the button size. The button property allow it to stretch "down" the included image to fit the button size, but I want to do the opposite : the thing is that my image is small, and I want it to grow if the button is bigger than the image.
How may I do this ?
Set the image as the background image of the button.
you can use property value Aspect Fit or something related to it.
I had same problem and after searching i found a good thread.
How do I scale a UIButton's imageView?
I will suggest you to set background image of button which will solve your problem.
And be careful if you are resizing image programatically it will take time to resize. If you have multiple images and you are resizing programatically do it on different background thread which will protect your main thread and GUI will not hang and set resized image on main thread.
I have two images.I want to display like where the first image end the next one should start.
both have same width but the height of the first one is variable .
I am not getting perfect code for it .
please help me
I am using one above another its displayed as a overlapped ??
Take 2 UIImageView and set their frame in such a way that when the first imageView ends you start the second imageView and in both the imageView set your image. Whatever height it is its gonna set in that imageView Itself....
hAPPY cODING...
I have a custom UIImageView class which I use to handle multi-touch events on the UIImageView. When the user touch begins, I want to increase the UIImageView's frame but keep the UIImage size fixed.
I tried changing the UIImageView's frame and then calling the drawInRect: method of UIImage to keep the UIImage's size fixed. But this is not working.
The contentMode for the UIImageView is set as ScaleAspectFit and as soon as I increase the frame size of the UIImageView, the UIImage size also increases (and is not affected by the drawInRect:)
Can someone please tell me how I can achieve this?
Thanks.
Adding more details
What I am trying to do is this
Place a UIImageView on the screen with the size same as the size of the image
When the user selects the image, anywhere he touches, the image edits as if the user is doing multi-touch with the image
If I increase the size of the imageview to detect touches any where, the image size also increases... Hope that makes things clearer!
Thanks
There may well be other ways to do it, but I think the UIImageView is doing what it's intended to do here.
What do you want the area of the view not covered by the image to look like? Be transparent? Have a solid colour?
Why do you want to do this? Is it to capture touch events from a wider area than that under the image itself?
If you have a good reason for needing to do this I would create a new view, probably just a plain UIView (with background set to transparent colour), and add the UIImageView to that. Make the plain view the one you resize.
I haven't specifically tried this, but I think it would work:
imageView.contentMode = UIViewContentModeCenter;