Custom back button with the < sign - ios

I have a screen in which the user is doing some actions.
When clicking the back button, I want to stop and show an alert to confirm this step.
I have 2 options:
Leave the native back button: < Prev screen and catch the -(void) viewWillDisappear:(BOOL)animated. when I'm doing that, It is too late to go back. I can't stop the back action, can I?
Replace with custom button. That's the easy solution, except I don't have the < on the button... Adding this sign as an image looks too cumbersome.
Does anyone have an idea how to solve this?

The right way is to create a custom UIBarButtonItem with the right type. Using an image is not painful at all.
And no, there is no use trying to prevent the pop action on UINavigationController. Also mind the InteractivePopGestureRecognizer as of iOS 7.

UIButton *button= [UIButton new];
//customize your button here
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]initWithCustomView:button];
self.navigationItem.leftBarButtonItem = leftBarButton;
customize your button with your title etc...

Related

How do I add an clear/redo button in a UIToolBar?

I have a "Clear" button. It clears 2 text fields back to being empty.
When the user clicks the "Clear" button once, I want it to change or become another button that adds back what it cleared. Like a "Redo" button.
How can I go about doing this? So far this is what my "Clear" button does:
- (IBAction)clearButton:(UIBarButtonItem *)sender {
_inputTextField.text = #"";
_outputTextField.text = #"";
_characterCount.text = #"0";
_characterCount.textColor = [UIColor blackColor];
}
I used to be able to use shake-to-undo, but after updating to iOS8 and xCode, no matter if I shake it, the redo menu does not pop up. It used to back in iOs7, but all it did was crash the application. Is there a way to fix this? I have it enabled but it just doesn't show up anymore.
Please don't berate my question. I tried searching but couldn't find it for a toolbar for iOS.
Hi I have create a new project on your requirement , have a look and reply :
https://github.com/ksbani/StapperRepo/archive/master.zip

UIButton Programmatically get Default Highlighted Style

I searched for this problem for a while and couldn't find anything about it, but eventually figured out my mistake, so I figured I'd post it here to help anyone with the same situation.
When creating UIButtons in Interface Builder, it automatically styles them for the highlight state (If you press and hold the button, it looks dim/lighter in whatever color you set it as); however, I was trying to create a button programmatically (just a normal text button) and wasn't achieving this result. If I pressed and held the button, the appearance was unchanged, although the button still worked.
The issue was that I was initializing the button with
UIButton *myButton = [[UIButton alloc]init];
instead of
UIButton *myButton = [UIButton buttonWithType: UIButtonTypeSystem];
Which is apparently the best-practice way of initializing a UIButton.

How to create a clickable button when it is below another view? (iOS)

My ViewController contains WebView and invisible button over (or below) the WebView. (see image). I want that the button to be clickable. But(!) in the case there are some links in the WebView, the links should be clicked, not the button.
How can I do it?
Similar issue discussed here:
Add UIButton in a UIWebView
However, in my case, I need links that are clickable also not be scrolling enabled.
If all you need is to be able to still drag the UIWebView around while still being able to receive a button press on a certain part on the view, you don't need to place a button below it in order to achieve that.
UIButton can still be able to receive touch even if it is completely transparent.
yourButton.backgroundColor = [UIColor clearColor];
[yourButton addTarget:self action:#selector(pressed)forControlEvents:UIControlEventTouchUpInside];
This way the button would only receive the press and will not affect your dragging of the web view - it will ignore the dragging but respond only to the press.
Tested on a scrollable view with a clear UIButton.
Hope this helps.

refresh button is not able to refresh UIView in monotouch iPad

i am new to iPad developer,
i have created two or three iPad application in objective c using Xcode 4.
but now i want to create iPad application using Monodeveloper tool in C# language...
in which, i want to insert Refresh button, on my NavigationBar,
here is my code snippet,
UIBarButtonItem button=new UIBarButtonItem(UIBarButtonSystemItem.Refresh);
NavigationItem.LeftBarButtonItem=button;
i am able to see refresh button on my NavigationBar, but when i click it, my view doesn't refreshes.
how to refresh view, any idea ?
Thanx In Advance !!
Any Help Will be Appriciated.
You are initializing a UIBarButtonItem without a handler. So tapping the button does nothing.
Try this:
UIBarButtonItem button =
new UIBarButtonItem(UIBarButtonSystemItem.Refresh,
(s, e) => Console.WriteLine("Refresh!"));
You can also assign it after initialization:
UIBarButtonITem button = new UIBarButtonItem(UIBarButtonSystemItem.Refresh);
button.Clicked += (s, e) => Console.WriteLine("Refresh!");
EDIT:
Inside the handler, you must implement your own "Refresh" code, depending on what it is you want to refresh. The UIBarButtonSystemItem enumeration merely defines the appearance of UIBarButtonItem buttons.

iOS Can't change UIBarButtonItem image properly

I'm having a problem when I try to change a UINavigationBar's "back" button custom icon. To achieve such a thing, I'm using the following code:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem* leftBtn;
UIImage* botonVolverImg = [UIImage imageNamed:#"boton_volver.png"];
leftBtn = self.navigationItem.leftBarButtonItem;
leftBtn.image = botonVolverImg;
}
But, when the view appears, you see this:
a busy cat http://www.timotteo.com.ar/boton.png
(You can see that the old button still appears at the back, plus the image I chose looks a bit streched)
I've been changing the imageInsets property, but that doesn't seem to work. I've also been reading the forum around, but couldnĀ“t find the exact solution.
Any suggestions are welcomed!
The image property for UIBarButtonItem doesn't correspond to the background image, only an image that provides additional context. If you're targeting 5.0+, your best bet would be to use -setBackButtonBackgroundImage:forState:barMetrics: to set a background for the bar button item.
To supplement Mark's answer, if your customer is requiring you to support iOS 4, you could create a UIButton that looks exactly how your customer wants it to (ie, just that image), and then use UIBarButton's initWithCustomView method to create your own back button. You can then have that button trigger popViewController or whatever appropriate action you need.

Resources