I'm trying to subclass a UIToolbar but the code doesn't seem to be working when I add the class to a UIToolbar in Interface Builder. What am I doing wrong here? I'm also looking for adding UIBarbuttonitems etc., this is just a test eg., daniel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//Customization//
UIImage *ToolbarBackgroundImage;
ToolbarBackgroundImage = [UIImage imageNamed:@"DefaultNavBar"];
[self setBackgroundImage:ToolbarBackgroundImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[self setShadowImage:[[UIImage alloc] init] forToolbarPosition:UIToolbarPositionAny];
}
return self;
}
-(void)drawRect:(CGRect)rect {
//do nothing//
}
If you are using a storyboard, you should also implement initWithCoder:
.
When a storyboard is being loaded, a decoder is used to create objects defined in the storyboard. initWithCoder:
comes from the NSCoding
protocol, and is a way for classes to deserialize themselves from coders. You can read about it in detail here.
If you wish to support both nibs and storyboards, there is a method available you can implement in your views, awakeFromNib
.