In my application in some view i have a picker at the bottom and tabBar i successfully hidden the tabBar but the problem is the frame allocated to TabBar is also hiding. so now the picker is displayed only half can any one help me out of this problem ?
use this method it works:
[actionSheetPicker showFromTabBar:self.tabBarController.tabBar];
I hope this helps you.
Don't hide tabbar if you hide it will so many create so many problems in this case
instead of hiding use this
[actionSheet showInView:self.tabBarController.tabBar];
You do not need to hide tabbar controller, you just need to add your action sheet in to tabbarcontroller
[actionSheet showInView:self.tabBarController.view];
Dont Hide tabbar and try bellow code
actionSheet=[[UIActionSheet alloc] init];
[actionSheet showInView:self.tabBarController.tabBar];
actionSheet.frame=CGRectMake(0, 100,480 ,232);
actionSheet.delegate=self;
picker=[[UIPickerView alloc] initWithFrame:CGRectMake(0, 50,480 ,175)];
picker.delegate=self;
picker.showsSelectionIndicator=YES;
[actionSheet addSubview:picker];
UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0,480 ,50)];
toolbar.barStyle =UIBarStyleBlackTranslucent;
NSMutableArray *ButtonArray=[[NSMutableArray alloc ]init];
Save=[[UIBarButtonItem alloc ]initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(save_pressed)];
UIBarButtonItem *titleName;
titleName=[[UIBarButtonItem alloc ] initWithTitle: #"Select Date" style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *space=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *cancel=[[UIBarButtonItem alloc ]initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancel_pressed)];
[ButtonArray addObject:cancel];
[cancel release];
[ButtonArray addObject:space];
[ButtonArray addObject:titleName];
[titleName release];
[ButtonArray addObject:space];
[space release];
[ButtonArray addObject:Save];
[Save release];
[toolbar setItems:ButtonArray];
[ButtonArray release];
[actionSheet addSubview:toolbar];
[toolbar release];
[actionSheet release];
Related
I want to add two buttons with custom image to Navigation Bar with some specific position.
I found solution But it is for Right/Left Navigation Bar Button.
My code for that is:
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
UIToolbar *tools = [[UIToolbar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 90.0f, 55.01f)];
// Add Pin button.
UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:#"Edit" style:UIBarButtonItemStylePlain target:self action:#selector(Edit:)];
bi1.style = UIBarButtonItemStyleBordered;
bi1.width = 45;
[buttons addObject:bi1];
[bi1 release];
// Add Hot Spot button.
UIBarButtonItem *bi2 = [[UIBarButtonItem alloc] initWithTitle:#"+" style:UIBarButtonItemStylePlain target:self action:#selector(Add:)];
bi2.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi2];
[bi2 release];
// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
[buttons release];
// Add toolbar to nav bar.
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
self.navigationItem.rightBarButtonItem = twoButtons;
[twoButtons release];
How can i do this?
UIView *vieww =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[vieww addSubview:yourBtn1];
[vieww addSubview:yourBtn2];
[self.navigationController.navigationBar addSubview:vieww];
And if you want to remove yourButtonView then make is global object;
in .h
UIView *vieww;
and in .m
-(void)viewWillDisappear:(BOOL)animated
{
[vieww removeFromSuperview];
}
Or follow this for more Link
if you are using >iOS 5, then use this.
UIBarButtonItem *btn1=[[UIBarButtonItem alloc] initWithTitle:#" + " style:UIBarButtonItemStyleDone target:self action:#selector(action1:)];
UIBarButtonItem *btn2=[[UIBarButtonItem alloc] initWithTitle:#" - " style:UIBarButtonItemStyleDone target:self action:#selector(action2:) ];
self.navigationItem.rightBarButtonItems=[NSArray arrayWithObjects:btn1,btn2,nil];
for < iOS 5 u can use following:
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 160, 44.01)];
tools.barStyle = UIBarStyleBlackOpaque;
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
[buttons addObject:btn1];
[buttons addObject:btn2];
[tools setItems:buttons animated:NO];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
Instead of adding toolbar, you can create one UIView, add two buttons on that view.
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:yourView];
If you want to do this in combination with using a storyboard, take a look at this question.
I want to display UIPickerView with UIToolBar on the top of pickerView with done and cancel button.Attached is the screen shot for the same.I also have tab bar controller in bottom side of view and I want to display pickerView over bottom bar thats why I am using uipickerView inside of actionsheet.Now my issue is how to dismiss that pickerView on cancelButton click which is added in UIActionSheet?
Following is the function to display pickerView :
-(IBAction)setMile:(id)sender
{
menu = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
// Add the picker
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,55,0,0)];
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES; // note this is default to NO
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(setMileCancel:)];
[barItems addObject:cancelBtn];
[cancelBtn release];
cancelBtn=nil;
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
flexSpace=nil;
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(setMileDone:)];
[barItems addObject:doneBtn];
[doneBtn release];
doneBtn=nil;
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
barItems=nil;
[menu addSubview:pickerToolbar];
[menu addSubview:pickerView];
[menu showInView:self.view];
//[menu showFromTabBar:[[self tabBarController] tabBar]]; this code is not working
[menu setBounds:CGRectMake(0,0,320, 545)];
[pickerView release];
[menu release];
pickerView=nil;
menu=nil;
}
I have following code on cancel button click
-(IBAction)setMileCancel:(id)sender
{
//[menu removeFromSuperview];
[menu dismissWithClickedButtonIndex:0 animated:YES];
}
// menu=nil;
Please comment this line, then it will work
Why are you using a UIActionSheet to accomplish this? Make the UIPickerView the inputView of a UITextField, and make the UIToolBar the inputAccessoryView of the UITextField. That way, you need only become/resignFirstResponder on the textfield to dismiss the UIPickerView and UIToolBar, without having any messy code! For more information, UITextField Reference. Hope that Helps!
I have resolved the issue.
Just remove following two lines from above code :
[menu release];
menu=nil;
I am adding a button to an actionsheet. That's easy, but in my case there are more than 5 and Apple does not accept more 5 buttons on action sheet. So I add a scroll view to the actionsheet and add buttons to the scrollview. But this view has two fixed buttons that is cancel and one other with some title.
Is this the right way to do this?
if you have more than five buttons, its better to use a customized table view in normal view and give UIModalTransitionStyleCoverVertical so that it will come like an action sheet
Use following code....
- (IBAction)actionsheetbuttonpress:(id)sender {
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
pickerData = [[UIPickerView alloc]initWithFrame:pickerFrame];
pickerData.showsSelectionIndicator = YES;
pickerData.dataSource = self;
pickerData.delegate = self;
[actionSheet addSubview:pickerData];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc]initWithTitle:#"DONE-A" style:UIBarButtonItemStyleBordered target:self action:#selector(DatePickerDoneClick)];
UIBarButtonItem *doneBtn1 = [[UIBarButtonItem alloc]initWithTitle:#"DONE-B" style:UIBarButtonItemStyleBordered target:self action:#selector(DatePickerDoneClick)];
UIBarButtonItem *doneBtn2 = [[UIBarButtonItem alloc]initWithTitle:#"DONE-C" style:UIBarButtonItemStyleBordered target:self action:#selector(DatePickerDoneClick)];
[barItems addObject:doneBtn];
[barItems addObject:doneBtn1];
[barItems addObject:doneBtn2];
//add more two button here...or you can add any no of buttons..
[pickerDateToolbar setItems:barItems animated:YES];
[actionSheet addSubview:pickerData];
[actionSheet addSubview:pickerDateToolbar];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
[barItems release];
[actionSheet release];
[pickerData release];
}
Hope, this will help you....chill
I know how to add a UISegmentedControl to a UIToolBar from within IB, but I am trying to do the same programmatically, because I am using a custom subclass of UISegmentedControl with doesn't have an XIB.
This is the code for the UISegmentedControl:
SVSegmentedControl *navSC = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:#"List", #"Calendar", nil]];
navSC.delegate = self;
[self.view addSubview:navSC];
[navSC release];
navSC.center = CGPointMake(160, 70);
I was thinking of doing something like [self.toolbar addSubview:navSC], but that didn't show anything.
You need to use the UIToolbar method – setItems:animated: (detailed in the documentation):
UIBarButtonItem *segItem = [[UIBarButtonItem alloc] initWithCustomView:navSC];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
[toolBar setItems:[NSArray arrayWithObjects:spaceItem,segItem,spaceItem,nil] animated:YES];
[segItem release];
[spaceItem release];
I have a UIViewController which is created programmatically. I include the following code in loadView. The toolbar is shown, but not the button I added. Any help would be appreciated please.
[self.navigationController setToolbarHidden:NO animated:NO];
UIBarButtonItem *actionB = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(actionBTapped:)];
[self.navigationController.toolbar setItems:[NSArray arrayWithObject:actionB] animated:NO];
[actionB release];
You want to set the items on the UIViewController itself, not its navigation controller:
self.toolbarItems = [NSArray arrayWithObject:actionB];
Try this:
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil] autorelease];
[items addObject:labelButton];
[items addObject:[[[UIBarButtonItem alloc] initWithTitle:#"YoutTitle" style:UIBarButtonItemStyleDone target:self action:#selector(actionBTapped:)] autorelease]];
[self.navigationController.toolbar setItems:items animated:NO];