Skip to content

Instantly share code, notes, and snippets.

@jacquesf
Created January 10, 2011 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacquesf/772504 to your computer and use it in GitHub Desktop.
Save jacquesf/772504 to your computer and use it in GitHub Desktop.
Method to add a title to an iPad silver-style UIToolbar, implemented as a category on UIBarButtonItem
//
// UIBarButtonItem+JFAdditions.h
//
// Created by Jacques Fortier on 1/10/11.
// Copyright 2011 Jacques Fortier.
// Released under the WTFPL (see LICENSE or http://sam.zoy.org/wtfpl/COPYING)
#import <UIKit/UIKit.h>
@interface UIBarButtonItem(JFAdditions)
- (id)initWithTitle:(NSString *)title width:(CGFloat)width;
@end
//
// UIBarButtonItem+JFAdditions.m
//
// Created by Jacques Fortier on 1/10/11.
// Copyright 2011 Jacques Fortier.
// Released under the WTFPL (see LICENSE or http://sam.zoy.org/wtfpl/COPYING)
#import "UIBarButtonItem+JFAdditions.h"
@implementation UIBarButtonItem(JFAdditions)
- (id)initWithTitle:(NSString *)title width:(CGFloat)width {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 23)];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.textColor = [UIColor colorWithRed:0x71/255.0 green:0x78/255.0 blue:0x80/255.0 alpha:1.0];
label.shadowOffset = CGSizeMake(0, 1);
label.shadowColor = [UIColor colorWithRed:0xe6/255.0 green:0xe7/255.0 blue:0xeb/255.0 alpha:1.0];
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:20.0];
UIView *labelContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 24)];
[labelContainer addSubview:label];
self = [self initWithCustomView:labelContainer];
[label release];
[labelContainer release];
return self;
}
@end
//
// UIBarButtonItem+JFAdditions.h
//
// Created by Jacques Fortier on 1/10/11.
// Copyright 2011 Jacques Fortier.
// Released under the WTFPL (see LICENSE or http://sam.zoy.org/wtfpl/COPYING)
#import <UIKit/UIKit.h>
@interface UIBarButtonItem(JFAdditions)
- (id)initWithTitle:(NSString *)title width:(CGFloat)width;
@end
//
// UIBarButtonItem+JFAdditions.m
//
// Created by Jacques Fortier on 1/10/11.
// Copyright 2011 Jacques Fortier.
// Released under the WTFPL (see LICENSE or http://sam.zoy.org/wtfpl/COPYING)
#import "UIBarButtonItem+JFAdditions.h"
@implementation UIBarButtonItem(JFAdditions)
- (id)initWithTitle:(NSString *)title width:(CGFloat)width {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 23)];
label.text = title;
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.textColor = [UIColor colorWithRed:0x71/255.0 green:0x78/255.0 blue:0x80/255.0 alpha:1.0];
label.shadowOffset = CGSizeMake(0, 1);
label.shadowColor = [UIColor colorWithRed:0xe6/255.0 green:0xe7/255.0 blue:0xeb/255.0 alpha:1.0];
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:20.0];
UIView *labelContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 24)];
[labelContainer addSubview:label];
self = [self initWithCustomView:labelContainer];
[label release];
[labelContainer release];
return self;
}
@end
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
@GerardRJ
Copy link

In UIBarButtonItem+JFAdditions.m there should be a "label.text = title;" or the title doesn't get displayed.

@jacquesf
Copy link
Author

jacquesf commented Jan 7, 2012

D'oh, thanks! Fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment