UIButton's Selected State not working in iOS7 - iphone

I am using Xcode 5's storyboarding to create an application, iOS SDK 7.0.
I dragged a button to the View. I want my button to display "A" by Default. Below are the button properties:
Type: System, State Config: Default, Title: Plain
I want my button to display "B" in selected state. So, the button properties that changed:
State Config: Selected
In the Button's Attribute inspector, under the Control, there is a property called Selected.
If I check Selected, instead of displaying "B", it just highlights like a marker over A, i.e, no character is seen.
I ran it in XCODE. WHen the button is not selected "A" is displayed as expected but when I select the button, instead of displaying B, the text portion of the button is highlighted with light blue color. Also, I never selected the Highlighted Content under the Control.
How can this be resolved, so that I can display the state correctly?

For anyone who set the button title by code, I found on iOS 7.1, you need to explicitly set title for various button states, while on iOS 7.0, setting title for UIControlStateNormal will also do for other button states.
// works on 7.0
[self.ibActionButton setTitle:NSLocalizedString(#"Register", nil) forState:UIControlStateNormal];
// works on 7.1
[self.ibActionButton setTitle:NSLocalizedString(#"Register", nil) forState:UIControlStateNormal|UIControlStateDisabled];

You need to set the title of the button to 'B' while you have State Config set to Selected in your storyboard. Then you need to connect an action to the button's Touch Up Inside event. Inside of that action, toggle the button's selected property.
When you check 'Selected' under the Attributes Inspector, you are just setting the button's initial selected state to YES. XCode also shows you what the button would look like in that state.

I found that this is a bug in XCODE 5, that is, when we check the selected property under Control for the button, it doesn't show the selected state on the Button. It works in the simulator we run the application. We would need to do a target-action for the button and toggle the selected state as below
- (IBAction)flipButton:(UIButton *)sender {
sender.selected=!sender.isSelected;
}

Related

Can't deselect DLRadioButton radio button

I'm using DLRadioButton but I can't deselect a radio button.
Here I want the user to check either or both of the buttons, but once selected they can't be deselected.
Make radio button using UIButton
and set selected and default image for UIButtons
Not get actions of both the radio buttons and on click of one change the state of buttons
There's an option to config it without an outlet, without switching to a UIButton.
If you do want to toggle, you can actually set isMultipleSelectionEnabled property on the button/checkbox to true.

What's the difference between UIControlStateHighlighted and UIControlStateSelected?

I am trying to set a state for UIButton.
But i don't know the difference between the UIControlStateHighlighted and UIControlStateSelected.
Could anyone help me out?
Thanks and best regards.
They can mean whatever you want them to, but in general they mean the following:
Highlighted = The user is currently interacting with something that will change once they stop interacting (e.g. holding down a button)
Selected = The item is current the active item in a group (e.g. The selected item in a segmented control). This can only be achieved by setting it programmatically.
UIControlStateHighlighted = it highlights the button with some flash(in button background) when the user taps.
UIControlStateSelected = it highlights nothing to that button.
From the official doc:
UIControlStateHighlighted Highlighted state of a control. A control
enters this state when a touch enters and exits during tracking and
when there is a touch up event. You can retrieve and set this value
through the highlighted property.
UIControlStateSelected Selected state of a control. For many controls,
this state has no effect on behavior or appearance. But other
subclasses (for example, the UISegmentedControl class) may have
different appearance depending on their selected state. You can
retrieve and set this value through the selected property.
Your button get highlighted in reaction of a touch event. It could then be on a selected state within a group (for segmented control).
Highlighted is typically applied transiently when the control is being touched, selected is a more permanent state. Imagine a checkbox type button which dimmed while it was being touched - dimming is highlighted, ticked is selected, unticked is unselected.
Typically you'd never set highlighted status manually as the system will be setting/unsettling it in response to touches, whereas selected is safer. This particularly applies to buttons.

Want to see the image only in iPhone

I have a button connected to an action.
When I set the background image on that button, the result is not visually appealing. I want just to see the image not the button but I want the ibaction functionality of that button.
Please help
You need a button with type UIButtonTypeCustom (this will stop the default button appearance from drawing). You can do this in interface builder or in code (although you can't change it once the button is initialized).

touch effect for Button in iphone

how can i just change the color,of a button when i set the focus on the button in iphone.
I mean to say , for example we have 5 buttons, and i am just setting the focus on each of the button. i want those buttons to be higlighted with different color.
but when press or touch up inside the utton, the navigation is made to the respective forms, that is set for that button.
you can write method, for example, let it be
- (void) changeButtonState:(UIButton*) buttonToChange;
then you can call it in your onBtnClk method for button you need. in that method you can change image for your button's UIControlStateNormal mode. and if I understand right, you can use toolbar or tabbar instead of buttons.
Guess you have already asked this issue differently here..
But have you checked the answer?? You can use any of those methods at your will!

How to control display in UIPickerView using selected state of button

hi i have used UIButton and also UIpickerview,when i select value(select team) ,the value is changed(india).but
when i hold the button(india) ,the value is changed to initial value(select team).if i release the button from pressing ,the value is changed(india).but i want to do when i hold , the button must show (india) ...i want to use selected state configuration...anyhelp?
What is value here? UIPicker's value? or it's some other control in your view?
Check out Highlighted state for UIButton in Interface Builder... hope this helps!