Cocoaheads Sydney Last night

6 views
Skip to first unread message

Cameron Barrie

unread,
Feb 2, 2012, 6:07:24 PM2/2/12
to cocoah...@googlegroups.com
For the guy last night who was asking about a custom back button, here's some code from a recent project that creates and uses a custom back button in the nav bar. 
- (void)viewDidLoad {
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = [UIImage imageNamed:@"back-button-item"];
    [backButton setBackgroundImage:image forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backButton setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];

    

    [backButton setTitle:@"Back" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backButton setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
    backButton.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.f];
    backButton.titleLabel.shadowOffset = CGSizeMake(0, -1);
    [backButton setContentEdgeInsets:UIEdgeInsetsMake(0, 7, 0, 0)];

    

    UIBarButtonItem *backButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:backButton] autorelease];
    [self.navigationItem setLeftBarButtonItem:backButtonItem animated:NO];
}

I normally create a custom subclass of UIViewController and then inherit any other controller that wants to use this back button from this controller(and any other NavigationBar skinning hacks). There are cleaner approaches using method swizzling but this way works for me, and it's fairly simple to understand. 

So for instance, the inheritance chain looks like this:
UIViewController -> BILBaseViewController -> BILHomeViewController

BILHomeViewController is added to a UINavigationController. Other view controllers also inherit from BILBaseViewController and then the back button is displayed.

The back methods looks like this BTW:

- (void)back {
  [self.navigationController popViewControllerAnimated:YES];
}

Hope this helps, give me a shout if not.

Cameron

hmujtaba

unread,
Feb 2, 2012, 11:13:49 PM2/2/12
to Australian Cocoaheads
yes I stopped using the default Nav Bar since long as well (thanks to
our creative designers)

Also, mostly I use my custom Scrollable Tab Bar in most of the
projects (again thanks to our creative designers)

One more thing to add on from last night,

I have lately been using iPad2 mirroring with Apple TV for my presos.
For the concern Mark pointed out about the Wifi Connection, I always
take my own Airport Express. (Has never failed me)
Key notes on iPad is wonderful, if you touch the screen for a couple
of seconds it even gives that red laser dot effect
I used to hate MAKING presos but love to make them now on the iPad.
(no seriously, I do)
Reply all
Reply to author
Forward
0 new messages