I've working on an app and I built the interface visually and I have an image on the top that covers the entire view including the buttons underneath, the problem I am having is the buttons are still able to be clicked even whilst the image is covering them. Is this supposed to be happening, or am I missing something really simple?
Set the userInteractionEnabled property of your image to YES, so that it will intercept all touches.
Disable button by using:
[button setEnabled:false];
You can also hide it i guess if you aren't using it
[button setHidden:true];
Related
In IB, the button size and location have been set perfectly well using autoLayout. But when I try to change the button image using the following
if (need_Update) {
[_updateButton setImage:[UIImage imageNamed:#"ipad_012_01_update2.png"] forState:UIControlStateNormal];
}
else {
[_updateButton setImage:[UIImage imageNamed:#"ipad_012_01_update.png"] forState:UIControlStateNormal];
}
the button size has been changed. I wonder why would that happen? And how could I fix it?
I mean, for example, the original button image is iPad_012_01_update.png, and it displays perfectly. When the need_Update value is YES, and the button image is changed to ipad_012_01_update2.png, but the button size is also changed.
Thanks in advance!
Summary
Using Background Image is a very good way to prevent unwanted size changing!
Also, there's a lesson: If you do want to use button image instead of button background image, be sure that the two button images are of the same resolution! This will reduce the chance that the image is resized itself.
Try following
if (need_Update) {
[_updateButton setBackgroundImage:[UIImage imageNamed:#"ipad_012_01_update2.png"] forState:UIControlStateNormal];
}
else {
[_updateButton setBackgroundImage:[UIImage imageNamed:#"ipad_012_01_update.png"] forState:UIControlStateNormal];
}
Hope this helps
The background image is scaled to fill the bounds of the UIButton, and is displayed behind the title. The foreground image is not scaled, and displayed next to the button title. So try to set the backgroundImage of a button.
UIButton image and background image, which one to use for custom image?
From the looks of it, it seems like your image is extending beyond the bounds of the button, so to you it looks like the button size is changing.
To test this, try setting the clipsToBounds to YES for the button.
It will clip anything that is going beyond the bounds of button.
So you will be able to analyze it in a better way and decide accordingly about how you want to move forward.
I have an ImageView with a picture and a button centered within it. On the button I have a different UIImage and the background on the button is white. In Attributes Inspector I have selected the UIImage for the button and made the button custom but still I have white background on the button.
I want the background on the button to be the same as the picture on the ImageView. I thought it was enough to change the button to custom. I am using Xcode 5.0.2, is there anyone that could help me with this. This is what my ImageView + button looks like now:
And these are the settings for the button:
If you're asking how to make background for the button clear, from within the Attributes Inspector scroll down to the View section and change the background to Clear Color from the dropdown menu.
Also make sure your .png has a transparent background. If you've already set the background to Clear Color the issue could simply be that your .png has a white background rather than a clear one.
try
[button setBackgroundImage:[UIImage imageNamed:#"name" forState:UIControlStateNormal]
Add image that you use for ImageView to Background properties of your button.
The following should do:
yourButton.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"yourImage"]]
I have a set of invisible UIButtons on the screen. When I say invisible I mean set to 'custom' without an image. I would like to make so that when the button was pressed it glowed for 1 second, so that the user can see he has pressed a button. How can I do this?
Use a blank image for UIControlStateNormal. Make an image for UIControlStateHighlighted which is your glow.
Rethink this design, because it doesn’t sound like it will fit well with the direction iOS 7 is going.
I put a button over my imageview. So it is a custom button and have nothing inside of it. It is invisible. I cant change my structure so I have to put that invisible buttons on my imageview.
My question is is it possible also to having highlight effect of the button? Because when I press the button everything is ok. It is working like a charm. But as expected there is no highlight effect. How can I have it?
Try setting showsTouchWhenHighlighted of UIButton to YES. I hope this was what you were looking for.
You set the highlighted image for button by below code.
[sender setImage:HIGHLIGHT_IMAGE forState:UIControlStateHighlighted];
I ended up by using a black over image with %50 opacity.
I'm trying to change the appearance of my UIButtons int the view as well as UIBarButtonItems in the NaviBar or toolBar or SegControl.
And here are 2 questions.
NO.1. How can I set customed background pictures to the buttons I mentioned while I can change their titles programmaticly? I mean I found that if I set the background of a button, the title seems to be concealed by the background image?
NO.2. I tried to add the text of the title directly on the png, ( which is actually a imperfect way since I need to change the title during the runtime). Anyway it works out both the image and the text, but the resolution seems to be reduced because the text became sort of blurred.
Can anyone give me some advices how to achieve it? Thanks a lot!
NO.1 The button title should not be obscured by the background image. Are you setting the button's image in code like this:
[btn setBackgroundImage:image forState:UIControlStateNormal];
? You may be instead setting the button's image property (which is different from its background image).
NO.2 You really don't want to be adding text to the button PNG, for the exact reason you mention. Buttons in iOS are designed to display images and text the way you want - put your energy into getting the built-in buttons working the way they should. There are umpteen billion tutorials out there about how to do this.