initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl not working - iphone

I am creating a barbutton item and adding it to my navigation controller toolbar
UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:#selector(pageCurlAction:)] autorelease];
And the barbutton item is rightly loading with the toolbar in my viewcontroller.Now, I push a new viewcontroller into my view and when I pop the viewcontroller, my barbutton item with the page curl shrinks and and the page curl image is missing on the barbutton.
I tried changing the
initWithBarButtonSystemItem
with
UIBarButtonSystemItemPlay, UIBarButtonSystemItemPause, UIBarButtonSystemItemFastForward
etc. But, it works fine with them. Its just the page curl icon thats not being loaded. Any reasons for this?

From the iOS Human Interface Guidelines:
In addition, you can use the system-provided page curl button in a toolbar (for more information, see the documentation for UIBarButtonSystemItemPageCurl in UIBarButtonItem Class Reference). The page curl button is not available for use in a navigation bar.
(Emphasis added.)

Even if you use a UIToolbar, this problem can appear. It turns out the order in which you do styling and adding of toolbar items matters.
In my case I had to change from:
[self.toolbar setItems:items];
self.toolbar.tintColor = [UIColor grayColor];
to:
self.toolbar.tintColor = [UIColor grayColor];
[self.toolbar setItems:items];
in order for UIBarButtonSystemItemPageCurl to start working on iOS 4.3

Related

add multiple UIBarButtonItems to UINavigationItem in Storyboard?

It is easy to add a single UIBarButton item as you can see here in my Storyboard. But I want to add several and it seems I cannot using the Storyboard?
Which is annoying because then I lose the whole nice overview of the Storyboard and it's Segue's.
Is this the case? First project using Storyboards so I figured I might be missing something.
In XCode 4.6 (at least), you can drag a plain view onto the navigation bar (on whichever side you want multiple buttons), then drag a toolbar on top of that. Once you've done that, you can place multiple bar button items on the toolbar, and wire them up to actions / segues, etc, as normal. Make sure you have the view and toolbar both set up for default (transparent) background color.
In Xcode 7 you can finally just drag multiple UIBarButtonItems to the UINavigationItem directly in Interface Builder.
See WWDC 2015 Session 407 video titled:
Implementing UI Designs in Interface Builder
https://developer.apple.com/videos/wwdc/2015/?id=407
Try this
-(void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *editBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:#selector(editAction)];
UIBarButtonItem *saveBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:#selector(saveAction)];
self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:editBarButtonItem, saveBarButtonItem, nil];
}
We also need to implement the methods editAction and saveAction.
-(void)editAction
{
NSLog(#"edit button clicked");
}
-(void)saveAction
{
NSLog(#"save button clicked");
}

custom UINavigationBar background in MFMailComposeViewController

I have a need to use a custom background for the UINavigationBar in a MFMailComposeViewController. Previously I was using a category on UINavigationBar to achieve this throughout my app, but Apple specifically requests that you do not do this. Additionally this may or may not work in future versions of iOS that are currently under NDA.
I am now using a subclass of UINavigationBar to achieve the look I'm after in the rest of the app, but I can't see any way to use this with the MFMailComposeViewController. Any ideas?
Note: I'm aware of methods to do this in a future version of iOS, but this needs to be built against a current version (4.3) of the SDK.
I just ran across this -- you can dynamically inject the class a view controller uses using object_setClass.
#import <objc/runtime.h>
object_setClass(mailController.navigationBar, [YourNavigationBarSubClass class]);
You can customize the nav bar's titleView with a custom view using the code below. Expanding upon this idea, you may be able to resize the titleView to cover the entire navigation bar and use a custom background in that to simulate a custom navbar background.
The only possible sticky part I can think of is that you need to make sure the titleView sits behind the buttons in the toolbar.
Once you have your MFMailComposerViewController reference, here is the code to customize the titleView:
[self presentModalViewController:controller animated:YES];
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(//set size to navbar size)];
[backgroundView setBackgroundColor:[UIColor colorWithPatternImage://your custom image ]];
controller.topViewController.navigationItem.titleView = backgroundView ;
[controller release];
The mail composition interface itself is not customizable and must not be modified by your application.
check apple reference for more info...
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
but we can customizable the mail composition as given oin the above answer....
After some hacking and testing, still not manage to customize the button. But this is the closest I can get, by setting the tint color of mail controller.
Try accessing them through mailController.navigationBar.items, which is an array of the bar items.
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
mailController.navigationBar.tintColor = [UIColor brownColor];
Although it would be nice to get more control over the appearance, I don't think there is a clean method. When you cant change it...hide it:
NSDictionary *attributes = #{NSForegroundColorAttributeName: [UIColor clearColor]};
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

How can I add an "add contact" button like the Contacts application?

How can I add to my app that little "plus" button that the Contacts application has in the upper right hand corner of the window?
I would like to be able to hit that button and bring up a screen to add a new entry to the table view.
What you're talking about is a UIBarButtonItem.
Here's an example of how to set one up in code:
UIBarButtonItem * addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(showContactView:)];
[self.navigationItem setRightBarButtonItem:addButton];
[addButton release];
When tapped, the button will call the follow selector.
- (void)showContactView:(id)sender {
// Show new contact view.
}
Tom Irving is completely right. It is a UIBarButton and you can configure as he has said. It can be added to a UINavigationBar or UIToolbar as per your requirement.
Hope this helps.
Also dont forget to release this button because some times it causes a crash if you dont release the button instance.

Is it possible to change UIBarButtonItem title and style in runtime?

In one project, I hope to change UIBarButtonItem and style in runtime
editBarItemButton links to a UIBarButtonItem which original status are
style:UIBarButtonItemStyleBordered
title:Edit
if I press the bar item button, it will execute the codes below:
[editBarItemButton setStyle: UIBarButtonItemStyleDone];
[editTarBarItemButton setTitle:#"Done" ];
but neither the style nor title has changed.
Welcome any comment
Thanks
interdev
You cannot change the style of a UIBarButtonItem after it has already been initialized.
Old thread, but I am successful in changing the title for a UIBarButton item in a Navigation controller using the following:
[[[self navigationItem] rightBarButtonItem] setTitle:#"List"];
Just remove the old buttons
Create new buttons with the styles you want
Set the new buttons
What you want to do is something like this (that preserves localization for you app as well):
- (void)setBarButtonTo:(int)type
{
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:type target:self action:nil];
[self.navigationItem setRightBarButtonItem:add];
}
Where type is one of the system supplied, as UIBarButtonSystemItemDone or UIBarButtonSystemItemEdit. Hope this helps. :)
PS: I'm aware it's an old question, but it lacked a proper answer.

How to set the button created in the navigation bar as custom in iphone?

I am new to iphone development.I have created a UIBarButtonItem on the navigation bar.I want to set the proper to custom. There is no property as custom for "style:" attribute.Please help me out.Thanks.
leftbutton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"LEFT.png"] style:UIBarButtonItemStylePlain target:self action:#selector(leftbutton)];
self.navigationItem.leftBarButtonItem = leftbutton;
[self.navigationItem]
[leftbutton release];
If you just want to display a .png file inside the usual button frame from Apple, then your code is ok. If your png file is not displaying, just check if it's valid.
If you want to make your own button, you can use -(id)initWithCustomView:(UIView *)customView
Check this post for an interesting sample code :
Custom Bar Button Sample Code
You can create item with - (id)initWithCustomView:(UIView *)customView method with whatever custom view you want.
UIBarButtonItem has 4 initializers which cover all you will ever need:
-initWithBarButtonSystemItem:target:action: for standard (built-in items);
-initWithTitle:style:target:action: for buttons with title and no image;
-initWithImage:style:target:action: for buttons with image and no title;
-initWithCustomView: for any UIView subclass, Apple's or your own.
The style property makes sense only for standard buttons.