Can I add an action to the Navigation Bar's title view? - iphone

I have a vision for something that I want to achieve, but I don't know if it is possible. Basically, I want my navigation bar's title (the one that is colored and formatted all pretty) to act as a button. I want to be able to press the nav bar title text, and be able to respond to that as a normal action.
Is this possible? I have tried a number of things, and have gotten the blank area to respond to touch as a button, but I can't get the button and the pretty text to be there together.
Thanks!

Create an UIButton with a transparent image and put it over the navigation controller

Related

How to detect tapping on the gray (dimmed) background in UISearchDisplayController

I am working on a iOS project where I want to implement a search functionality. I'm using UISearchBar and UISearchDisplayController and I would like to make UISearchBar implicitly hidden. When user taps on the UIBarButtonItem, the search bar will appear and "becomeFirstResponder", whereas when user clicks on the Cancel button in the search bar, it should disappear.
The appearing is working correctly, but I have a problem with disappearing. I managed to hide the search bar when user taps on the Cancel button (searchBarCancelButtonClicked method), but I'm unable to hide the search bar when the grey (dimmed) background in UISearchDisplayController is tapped. As far as I know, there is no method to detect this event, so it is necessary to apply some hack. Do you know any, or what is the best way to detect tapping on the gray background?
So I've finally worked it out. Apart from the searchBarCancelButtonClicked:(UISearchBar *)searchBar, it is also necessary to hide the search bar in searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller. It looks this callback is called even when the gray (dimmed) background is tapped, so it can be easily used for hiding the search bar.
UISearchDisplayController usually consists of a UISegmentedControl, the UIResultsTable and the keyboard. The results table is where you want to detect this touch to dismiss. With that being known, maybe you can add a transparent UIButton to that view that dismisses first responder, or Maybe you can add a UIGestureRecognizer on a transparent view that achieves the same effect? Just thinking off the top and have not tried this myself, if it works for you im glad !

How to change UIActionSheet view?

As I observed that UIActionSheet is always appearing from down side in iPhone,
but in some app, as I saw in AlarmClock, then two button became visible, one from upside and second from downside of iPhone,
What is that exactly, I can't understand, as far as I feel, it looks UIActionSheet,
I want such appearance for one of my app....
Help!
Yes just like Ole said, you can't customize UIActionSheet . But since it is just a simple subview you can create your personal "action sheet" by subviewing and animating. So if you want a button to appear on the top and one on the button, then create two UIViews resize them to the right size for your button, add your action sheet style background or any other background, add your button, connect your IBActions to the buttons and your IBOutlets to the views. Then when you want the buttons to appear animate them onto the screen (using sone CGRect, animation time and finally [UIView commitAnimations])
Probably just one or two custom views with a custom animation. UIActionSheet is not customizable so if you want something else than the default behavior you have to write it yourself. It's not that difficult.

How to have a bordered UIBarButton Item with both Image and Text - Like in Mail

In the Mail app on iPhone, when the user taps Edit, the toolbar shows two buttons, Delete and Move. These buttons have both image and text while appearing as bordered.
I tried to recreate this effect, but I have not really succeeded. Here's what I've tried:
The obvious way of setting the image and text properties. This results in some weird button with the image on top and the text below it.
Initialize the UIBarButtonButton with a custom view set to an instance of UIButton (described here). This button can then not be set to be bordered, instead it appears as a flat view (without shadows either).
I could obviously create a button and then add an UIImageView as a subview to the toolbar, but then I have to care about device rotation and some other stuff I would like to avoid. Also, I think Apple doesn't do it this way; when you select an email in Mail while in editing mode, the button label is updated with (-number-), which moves the image slightly to the left. It looks like the text and the image belong together.
So I wonder whether anybody did something like this?
Most likely these are UIButtons with stretchable image backgrounds. That's how I would do it.

Display a box with contents in Iphone View

I am working on an app which displays user information on the home view. Its a regular tab bar application, which brings up the home view on load. I need to display something like,
Hello Joe,
Your current points are : xxx
I would like this to be in a white curved background box. (The background for the view is blue). Is there something like a UIPanel or something like that. I would really like to avoid having another view or a webView, not sure if thats going to affect the speed of loading the page.
If there were a UIPanel control it would derive from UIView, so I'm not sure why you want to avoid another view. If I'm understanding you, it sounds like you want a custom alert window of some sort. You could just use the UIAlertView control to display your message, but if you are dead set on a custom look, then you will need to use a view.
This shouldn't affect performance noticeably if you are just displaying some text with maybe a button on a custom image. Especially if this is just a tab bar application with nothing too crazy happening in the background (animations, etc.).
I would suggest creating a View either in code (this will be slightly faster, but once again probably not noticeably so) or with Interface Builder that has a black background with an opacity of like .2-.5 and on that view adding a UIImageView set to your custom image (a png of a white curved box with transparent corners). Then put a UILabel with your text and a button to dismiss it.
On load just instantiate the above view and add it to your current view. It will show your message modally. Then capture the button tap event to have it remove itself from it's superview.
There are plenty of examples of how to do exactly this out there and there are even other ways of doing it than what I've suggested. If you need further assistance let me know.

iPhone UIActionSheet with UISwitch and UITextField

I'm just looking for advice with this as I have no idea where to start but I think a UIActionSheet is probably best.
What I'd like to have is a pop up window (in my head I picture it as being translucent and dark gray). It will not take up the whole screen and the view underneath will still be visible.
In the pop up section there will be a textfield (with several lines) and underneath this there will be a number of UISwitches.
The pop up will be scrollable and will end with OK/Cancel buttons at the bottom.
Like I said, I really have no idea where to start with this but any advice is more than welcome!
A UIActionSheet is probably not what you are after in this case (although you may want a similar look and feel). Think of an action sheet as a traditional modal OK/cancel/Yes/No type dialog box:
Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task.
From the sound it of it, you need to create a UIView in InterfaceBuilder with a semi-transparent background and various child controls (UISwitches and UITextFields). You create your view using the XIB you have configured and add it as a subview of your UIViewController's view. If you want to mimic the animation you get from an action sheet, you can do that with an AnimationBlock.