I want to enable or disable the button. Is there any way to drag the outlet of UIButton on to the Bar Button? I tried, I could do that. How to enable or disable the button if I can't connection them together?
Thanks!
You might use the UIBarButtonItem.
Related
In my mapkit app, I would be able to enable/disable programmatically buttons created via Interface Builder. The idea is enable a one or more button if a annotatios is selected, and disable if not. for example, in my, an action:
-(void)traceRoute:(id)sender{
//trace route between user location and annotation selected
}
is defined in order to trace route between user location and annotation mapkit. In IB, defined a button and linked to that action, it works. But I do not understand how I can enable a button not defined programactically but in the interface builder. Any help is apreciated!
try this one
-(void)traceRoute:(id)sender{
UIButton *button = (UIButton *)sender;
[button setEnable:YES];
}
IN the IB we do have option of enabled. And if we want to enable/disable it according to the conditions, then we need to create the outlet of button and handle it programmatically.
You need to define that button in the view controller interface:
IBOutlet UIButton* myButton;
Connect this outlet to your button in the IB, then you can do:
[myButton setEnabled:YES];
I have a UIViewCOntroller, and in that i have a button and a text field. When i click the button i display a UIToolBar.
Now when i click anything in the background (the textfield or the blank view) i need this UIToolBar to disappear. How can i do this programmatically ?
I know how to add a UIToolBar but all what i need to know is to hide it when the user clicks on the background.
I don't think i will have to paste any code here or show my workings so far, coz i have no clue how to get this done
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setToolbarHidden:YES animated:YES];
}
May be it can help you....
You will need to capture a touch on the views outside of your toolbar to achieve this. If you have a custom UIView base class that all of your other views use, you might start there. Otherwise, perhaps use some sort of toggle to show/hide your toolbar instead in your UIViewController.
The easiest way to do this is to make a single large clear button that is behind the first button but above everything else. Normally have it set to hidden but when you show the toolbar unhide the button as well. When the button is clicked have it hide the toolbar and its self. No need to do anything crazy like sub classes.
Apple frequently uses a left arrow icon in the their navigation controller "back" button, rather than the word "back" or other text:
It doesn't seem possible to assign an image to this special button with the standard SDK. Am I missing something obvious? If not, what's the most effective way of achieving this? (Can it be done without Photoshopping the whole button in multiple states?)
Thanks.
Create a UIBarButtonItem with the image and assign it as the backBarButtonItem property of your view controller's navigationItem.
You can use -initWithImage:style:target:action: of UIBarButtonItem and put your image instead.
- (id)initWithImage:(UIImage *)image
style:(UIBarButtonItemStyle)style
target:(id)target
action:(SEL)action
I like the look of the UIBarButtonItem buttons. Is there a way to put these on a screen without using a UINavigationBar or UIToolbar.. so the button are just placed straight onto a view? (or possibly put them onto on nav bar or toolbar whose content is invisible, except for the bar buttons)
As they do not inherit from UIView and don't expose a view property (except for those customView based ones), you cannot simply add them onto views out of the box. Also, they might need to "talk back" to their bar container, which would fail anyway. Go with UIButton with custom image.
You cant use Bar button directly on button if you like those button then you can pick the image for same and use that with the round rect or custom button.
I have added a custom button (subclass UIButton) to my navigation bar but the button does not change states when clicked.
The button is configured correctly as it does work in, for example, a table view.
All advice is welcome.
Have you tried subclassing UIBarButton instead of UIButton?
I got it working. What I forgot to implement was the method to change the button selection states.