when i press the button i get the blue color ,
is there any way to just avoid getting that blue color when i press the button.
sets the button look to be consistent regardless of the state
[UIButton1 setBackgroundImage:[UIImage imageNamed:#"ButtonBack.png"] forState:UIControlStateSelected|UIControlStateNormal|UIControlStateHighlighted];
[UIButton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected|UIControlStateNormal|UIControlStateHighlighted];
You could add a background image of the button for the state UIControlStateHighlighted. The background image would be the same as the non-highlighted state.
Related
Im trying to troubleshoot my first iphone app and Ive run into a propblem i just dont get. I have lots of buttons on a view and when you click them their text colour changes from black to blue. I assume that I could fix this by just setting the textColor property every time the button gets pushed to set it back to black but I feel like there must be something else going on.
Anyone know why my buttons are changing color by themselves?
It is possible to have different title colors depending on button state. Set them using the following method of the UIButton class:
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state
F.e.
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
where UIControlStateNormal is the default, not pressed, button state, and forState:UIControlStateHighlighted represents the pressed state. But there are more, and can be combined with binary sum, such as (UIControlStateHighlighted | UIControlStateSelected).
I have a button with a curved image set as its foreground image. It looks like:
Now when the button is on pressed state, it shows up like this:
notice the grey rectangular color coming up around the edges. Is there any easy way to avoid the grey background coming all over the rectangle ?
You need to set the property Shows Touch On Highlight to enabled.
Programmatically you can do that with:
[button setShowsTouchWhenHighlighted:YES];
How set image in button when ever click the button image show me that button
run.backgroundColor = [UIColor redColor] I try this but it doesn't work,
To set an image for a button while it is currently being touched (I think this is what you're asking). You use setImage: forState on the UIButton.
[myButton setImage:[UIImage imageNamed:#"myButtonGraphic.png"] forState:UIControlStateHighlighted];
You can control when the image appears using the different control states, one of:
UIControlStateNormal
UIControlStateHighlighted
UIControlStateDisabled
UIControlStateSelected
UIControlStateApplication
UIControlStateReserved
If you use UIControlStateNormal, the image is displayed all the time, and when the button is currently being touched it will appear dimmer which for a lot of cases is good enough to indicate to the user that they are selecting that button and that it's a real touchable 'thing'.
Currently when you use a UIButton and press down on it, it gives the button a dark overlay as an indicator that the button was pressed. I don't want this as I am implementing my own pressed state.
How can I remove this default?
You could also set the appropriate property:
button.adjustsImageWhenHighlighted = NO;
You should be able to set it by setting the image for the control state. Think its
[button setBackgroundImage:[UIImage imageNamed:#"Selected_day.png"] forState:UIControlStateHighlighted];
I have created five buttons in the view controller. If i clicked the button it goes to the corresponding view. Now i want to display the button in highlighted state when it is clicked. It should go back to the normal state only when i click the other button. I have set the another image for highigthting buttons when i clicked it, but it shows that highlighted state only one sec. Now i want to display the buttons highlighted till another button is clicked. Same like a Tabbar operations.(I have used buttons instead of tabbar for the requirements).
Now i have used the following code,
void didLoad
{
[btn1 setImage:[UIImage imageNamed:#"ContentColor.png"] forState:UIControlStateHighlighted];
[btn2 setImage:[UIImage imageNamed:#"bColor.png"] forState:UIControlStateHighlighted];
[btn3 setImage:[UIImage imageNamed:#"ShColor.png"] forState:UIControlStateHighlighted];
[btn4 setImage:[UIImage imageNamed:#"PicturesColor.png"] forState:UIControlStateHighlighted];
[btn5 setImage:[UIImage imageNamed:#"infoColor.png"] forState:UIControlStateHighlighted];
}
Please help me out.
Thanks.
You should be manipulating the image for selected state, not for highlighted state. Highlight will be unset on touch up or touch outside, as you have seen, whereas selected is persistent.
Simple solution would be...
on every click on any button change it's image (For normal state) to highlighted image for that particular button and set other 4 button's image to normal image...
It sounds like you should be using a UISegmentedControl with 5 segments instead of 5 buttons. It behaves this way already, a segment stays highlighted until you select a different one (unless you set the momentary property).