Is it possible to make the navigationcontroller title a button? - iphone

Is it possible to make the navigationcontroller title a button? but without a button look to it. I want it to be just text that if you click on it a view/actionsheet pops up from the bottom
If so, can you show me programmatically how I would make it a button?
Thanks

You can set TitleView of navigationItem to set a button as title.
Here is what i tried and got it working:
UIButton*button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(0, 0, 30, 20);
[button setTitle:#"Testing" forState:UIControlStateNormal];
[button addTarget:self action:#selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
[[self navigationItem] setTitleView:button];
But if you don't want it to look like a button, you have set the buttonWithType to custom and set its backGroundImage property.
in btnAction have your code to show the pop ups.

Related

How to align back button of the navigation controller to its left corner in iphone application

I have customized my navigation controller back button by adding image to it,but still I couldn't get back button in to navigationbar's left corner.I want to avoid the gap or the space between navigation bar's left margin and the backbutton.
Thanks for the help.
Here is the code you can use
UIButton* backButton= [UIButton buttonWithType:UIButtonTypeCustom];
//here in below you just need to pass the point where you want to place your button.
As you said you need space between navigation bar's left margin and the back button.
[backButton setFrame:CGRectMake(xOrigin, yOrigin, width, height)];
[backButton setImage:[UIImage imageNamed:#"imageName.png"] forState:UIControlStateNormal];
UIBarButtonItem * leftBarButton =[[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem= leftBarButton;
I hope it may help you.

Where to insert code that creates buttons programmatically?

I receive some JSON from the net and based on that data, I must create 2 or 3 buttons. Part of my gui is static and created in NIB (won't change), only the number of buttons will change. I found this code for making buttons in code:
//create the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//set the position of the button
button.frame = CGRectMake(100, 170, 100, 30);
//set the button's title
[button setTitle:#"Click Me!" forState:UIControlStateNormal];
Is this the right way? In which method of my viewcontroller should I put this code?
You can add the button whenever you want, as long as the view has been loaded already. The one thing you'd need to add to the above code is
[[self view] addSubview:button];
Using this code, you have a button on the screen, but it won't be able to trigger any actions. You'll probably also want to add:
[button addTarget:self action:#selector(someMethod:) forControlState:UIControlEventTouchUpInside];
You should add the buttons in the delegate/method that parses the JSON data.
Don't forget to add the created buttons to your view:
[containerView addSubview:button];

shopkick application UI widgets

Please see the link below.
http://itunes.apple.com/app/id383298204?mt=8
There are screen shots of showpick application. In that there is a collect button which is some what impossible to implement under ui tab bar. Can someone help me to figure it out how they have implemented it? Is that an actual UITabBar?
Thank you
I figured out a workaround. I basically add a dummy controller for the middle entry of the UITabBarController. And in viewDidLoad I add a button to the UITabBar like so:
tabBarButton = [[UIButton alloc]initWithFrame:CGRectMake(125, -10, 70, 33)];
[tabBarButton setBackgroundImage:[UIImage imageNamed:#"state-inactive"]forState:tabBarButton];
[topbarButtonScan setBackgroundImage:[UIImage imageNamed:#"state-active"]forState:UIControlEventTouchDown];
[tabBarButton addTarget:self action:#selector(tabBarButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[[[self tabBarController]tabBar ] addSubview: tabBarButton];

On Cancel Pressed of UISearchBar - Fire Custom Action in iPhone

alt text http://img216.imageshack.us/img216/2288/problem11.png
As given in the picture, I have an search bar in my application.
Now I want to handle my custom action on Cancel Taped.
-> On Cancel Taped -> PopViewController
-> On Cancel Taped -> Clear Search Text & Hide Search Bar Keyboard.
I don't know how to handle Cancel Tap?
Thanks in advance for helping me.
Ok ! I tried Something Different. I added a new button on Cancel Button.
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor=[UIColor clearColor];
[btn setFrame:CGRectMake(260, 5, 53, 32)];
[btn addTarget:self action:#selector(onCancelSearch:) forControlEvents:UIControlEventTouchUpInside];
[searchBar addSubview:btn];
Now. See Following image. but it is with RoundedRect Type, Instead Use TypeCustom - so it will become invisible.
alt text http://img269.imageshack.us/img269/4337/problem12e.png

UITextField leftView

Is it possible to set up a UITextField with a leftView so that if a user clicks into the UITextField the keyboard shows but if they click on an icon in the leftView another method is called (i.e., one that displays a UIPickerview)?
Have you checked that the leftFieldViewMode is set to something other than never
[textField setLeftViewMode:UITextFieldViewModeAlways];
Instantiate a button as u do normaly
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0,0,30,30)];
[btn setTitle:#"title" forState:UIControlStateNormal];
[btn addTarget:self action:#selector(BtnClick) forControlEvents:UIControlEventTouchUpInside];
Instantiate a textfield as you do normally
UITextField *txtfield1=[[UITextField alloc]initWithFrame:CGRectMake(10, 10,300,30)];
[txtfield1 setBackgroundColor:[UIColor grayColor]];
[txtfield1 setPlaceholder:#" Enter"];
To set a view in left side(there is right view also available)
[txtfield1 setLeftView:btn];
if u want the view to show always then below code does it
[txtfield1 setLeftViewMode:UITextFieldViewModeAlways];
if u want the view to show never then
[txtfield1 setLeftViewMode:UITextFieldViewModeNever];
if u want the view to show if the textfield is not edited then below
[txtfield1 setLeftViewMode:UITextFieldViewModeUnlessEditing];
if u want the view to show if the textfield is edited then
[txtfield1 setLeftViewMode:UITextFieldViewModeWhileEditing];
button click event and pop over
-(void)BtnClick
{
//Usual pop over coding goes here
}
Have you tried using a UIButton for this task? From the documentation for the leftView property:
If your overlay view does not overlap
any other sibling views, it receives
touch events like any other view. If
you specify a control for your view,
the control tracks and sends actions
as usual. If an overlay view overlaps
the clear button, however, the clear
button always takes precedence in
receiving events.
So create a UIButton instance, configure its appearance and actions as needed, then set it as the leftView property.