when i click on a button of my segmentcontrol i see interaction(i.e thing happen the way they should) but the buttons clicked don't gate darker (to show that they are selected). Any ideas why this happens?
There are two check boxes in the Segmentcotrol's Attributes setting in IB that might effect the behavior that you encountered: State: Momentary and Behavior: Enabled.
Related
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.
I have a UISearchBar (with UISearchDisplayController) as title view of UINavigationBar. There are also two buttons on either side of the searchbar within the navbar.
When clicking on UISearchBar, it becomes wider and covers the button on the right of it.
How can I stop it from becoming wider?
Things tried but didn't work -->
The widened search bar then becomes the original size if the device is rotated.
So, tried calling [searchBar setNeedsLayout] in -searchBarTextDidBeginEditing
All different auto-resizing mask options in IB
Edit: Didn't mention, but this is on iPhone (as we can put searchbar inside toolbar in iPad..)
Actually, taking hint from this answer if the search bar is put in UIView of desired size then this is set as title view of NavBar, it doesn't go wider !
But... Since you can't make cancel button to show/not show as you wish, I realized it's not so useful.
(As seen in this question/answer etc)
I have the weirdest issue today. I always use toolbar and bar button item button and never have problem. Here is the issue:
I have view and the bottom has toolbar. In the toolbar, I create two bar button items which are 'back' button and 'next' button. For some reason, when i build into simulator or iphone, those buttons are not sensitive like before. On other words, the buttons do not really work. I found out that the half part (top) of the buttons are working when you touch it or use mouse cursor to click it. But the other half (down) of the buttons are not working at all.
Anybody has this kind of issue?
Half of the toolbar means status bar's height. Double check your view's height and change according to your status bar.
I have a view that holds some UIButtons. Another view covers and hides the buttons. When the top view slides off to reveal the buttons (with an animation).. the UI draws the buttons grayed out until the top view no longer covers or overlaps the buttons at all.. causing an undesirable flicker from gray to the normal button color (white).
is there a way to keep the UIButton from rendering itself disabled while covered or semi covered by another view?
I dont think that its correct that a button is disabled while covered. What is happening is that when its covered, touch events are prevented from getting to the button, so the button cant get pressed. If the button is only partially covered, touch events to that part that are not covered can be received by the button and the button can be depressed. If you really wanted the button to work while it was covered (maybe you can relayer your views so the button is in front of the view instead of behind it?) you could hack your view and void its hit testing so it doesnt capture the touches.
Well, in lieu of actually finding the correct answer, I simply swapped out the buttons with UIImageViews and attached UITapGestureRecognizers to them... this solved the problem.
I am making multiple custom buttons that look much like this:
It is a simple button with either the green or gray in the "indicator view". What I need some explanation for is: In interfacebuilder there are four states a button can have; Normal, Highlighted, Selected and Disabled. When I provide images for everything except disabled I thought that normal would be when no touches were made on the button, highlighted is while you hold your finger on it and selected would be when after you release finger.
However I do not think thats right now. I use the touch-up-inside event. Is it correct that I need to set the selected/highlighted etc property on the button?
Thank you for your time.
You might want to set to selected and not highlighted.
Highlight is darkening the button for a fraction when touching the UIButton. UIButton can modify your image automaticaly so usually you don't need to provide a highlight image.
Disabled is when it is disabled.
Selected is when it is selected. You can invert the select flag on touch up inside event to make a state button.
[button setSelected:![button isSelected]];
Yes, you need to respond to the touch up inside by setting the button to highlighted.
Btw, it's "disabled" not deselected, but it doesn't sound like you need that state.