Tool Bar buttons Intially faded Out - ios

i have created a overlay view of tool bar on camera controller , i have added 5 buttons as per my requirments on tool bar ,
error is when i run the application toolbar items i.e button are intially faded and are invisible as : , the grey space is the defined toolbar , when i tap on the tool bar , the buttons actions are perfomed but buttons are not visible . Thanks in advance.
UIToolbar *toolBar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, width, 55)];
NSArray *items=[NSArray arrayWithObjects:
[[UIBarButtonItem alloc] initWithTitle:(#"Album") style: UIBarStyleDefault target:self action:#selector(selectAlbum)],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil],
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
nil];
[toolBar setItems: items animated:NO];
Above is reference code .

Related

UIToolBar is black for a split second on load

Every time I load up the UIView that holds the UIToolbar below (which is attached to the keyboard), it turns black for a second until the view fully loads, and then turns back to the standard white color. I'm stumped as to why this keeps happening.
Here's how I'm forming the UIToolbar:
[self.answerField becomeFirstResponder];
UIToolbar *toolbar = [UIToolbar new];
UIBarButtonItem *sectionButton = [[UIBarButtonItem alloc] initWithTitle:#"§" style:UIBarButtonItemStylePlain target:nil
action:#selector(addSectionSymbol:)];
UIBarButtonItem *paraButton = [[UIBarButtonItem alloc] initWithTitle:#"¶" style:UIBarButtonItemStylePlain target:nil
action:#selector(addParaSymbol:)];
UIBarButtonItem *flexSpacing = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSString *infoLabel = #"Select text to italicize. Always use italics.";
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:infoLabel style:UIBarButtonItemStylePlain target:nil action:nil];
[infoButton setEnabled:NO];
[toolbar setItems:[NSArray arrayWithObjects:sectionButton, paraButton, flexSpacing, infoButton, nil]];
self.answerField.inputAccessoryView = toolbar;
[toolbar sizeToFit];
Any ideas?

How to change distance between UINavigationBarButtons

I set two navigation bar buttons, and there is a space between it, how can I change this space to set buttons closer to each other?
I've tried to add third button with minus width, Here the code
self.editButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"Edit.png"] style:UIBarButtonItemStylePlain target:self action:#selector(editAction:)];
self.callButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"call_icon.png"] style:UIBarButtonItemStylePlain target:self action:#selector(editAction:)];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:nil] style:UIBarButtonItemStylePlain target:self action:nil];
spacer.width = -30;
NSArray *buttons = #[self.editButton, spacer, self.callButton];
self.navigationItem.rightBarButtonItems = buttons;
But it is not working; Any suggessions?
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -16;// it was -6 in iOS 6
[self.navigationItem rightBarButtonItems:[NSArray arrayWithObjects:negativeSpacer, requriedButton/*this will be the button which u actually need*/, nil] animated:NO];
hope this will work for you...
You can create a UIBarButtonItem with the style UIBarButtonSystemItemFixedSpace and add it to the buttons array.

How to center a UILabel in a UIToolbar

I have a UIToolbar in the interface builder. I made a connection to the UIToolbar using IBOutlets. In my code in the initWithCoder and viewDidLoad event I try to access the bounds.size.width property of the UIToolbar and it says 0. Eventually, I would like to center a UILabel inside the UIToolbar.
You should use UIBarButtomItem like this:
UIBarButtonItem *flexible1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] initWithTitle:#"Your Label String" style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *flexible2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[toolBar setItems:[NSArray arrayWithObjects:flexible1, titleButton, flexible2, nil]];

how to add two button in navigation bar with some space

I am adding two button in navigation bar they are working fine but i want space between them they are both combined i want a bit space between them
UIBarButtonItem *btnAdd = [[UIBarButtonItem alloc] initWithTitle:#"Add"
style:UIBarButtonItemStylePlain
target:self
action:#selector(Add)];
UIBarButtonItem *btnEdit = [[UIBarButtonItem alloc] initWithTitle:#"Add"
style:UIBarButtonItemStylePlain
target:self
action:#selector(Add)];
UIToolbar *rightToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
rightToolBar.backgroundColor = [UIColor clearColor];
rightToolBar.tintColor = [UIColor colorWithRed:40.0/255.0 green:48.0/255.0 blue:51.0/255.0 alpha:0.0];
NSArray *buttonsRight = [NSArray arrayWithObjects:btnEdit, btnAdd, nil];
[rightToolBar setItems:buttonsRight];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightToolBar];
You can add any of these two between your UIBarButtonItem
UIBarButtonItem *fixed = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]
Note that to set the width of a Fixed Space UIBarButtonItem, you need to set the .width property
[fixed setWidth:455.0f];

iOS - UIToolBar as inputAccessoryView for UITextView

I've added a UIToolBar with a UIBarButtonItem as inputAccessoryView for a UITextView. It works fine but the UIBarButtonItem is touchable outside it's frame, perhaps 50 pixels outside to the right. It's no big deal but it annoys me. Anyone know why?
This is my code (ARC):
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.barStyle = UIBarStyleBlack;
toolBar.translucent = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doneWriting:)];
[toolBar setItems:[NSArray arrayWithObjects:doneButton, nil]];
self.messageTextView.inputAccessoryView = toolBar;
In iOS 6 it seems to behave as expected.
Nice tip: If you want the button to appear on the right instead of the left, use one of these:
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
Then initialise the toolbar with:
[toolBar setItems:[NSArray arrayWithObjects:flexibleSpace, doneButton, nil]];
The toolbar seems to expand the active area of the buttons beyond their bounds if there are no other nearby buttons in the toolbar. Apple engineers must think it is better to try to guess where the user intended to press rather than not react at all.
I hope it helps you...
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
[keyboardDoneButtonView sizeToFit];
UIBarButtonItem* PrevButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 target:nil action:nil]; //<
UIBarButtonItem* NextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 target:nil action:nil]; //>
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(doneClicked:)];
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *fake = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil] ;
[keyboardDoneButtonView setItems:[NSArray arrayWithObjects: PrevButton,fake, NextButton,fake,flexSpace,fake,doneButton,nil] animated:YES];
Use Fake Item to get exact pinch location on Button...

Resources