ios - Subclassing UIToolbar and overriding drawRect: - UIBarButtonItems NOT displaying -
context
i'm using 'initwithnavigationbarclass' method initialize uinavigationcontroller custom toolbar, here line alloc init uinavigationcontroller
navigationcontroller = [[uinavigationcontroller alloc] initwithnavigationbarclass:nil toolbarclass:[questiontoolbar class]];
is class, "questiontoolbar", subclass uitoolbar , override drawrect, here drawrect method:
- (void)drawrect:(cgrect)rect { [super drawrect:rect]; uiimage *backgroundimage = [uiimage imagenamed:@"44px_background_red.png"]; [backgroundimage drawinrect:cgrectmake(0, 0, self.frame.size.width, self.frame.size.height)]; }
here pertinent code in viewcontroller attempt add uibarbuttonitems
uibarbuttonitem *spacer = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil]; uibarbuttonitem *beginitem = [[uibarbuttonitem alloc] initwithtitle:@"begin quiz" style:uibarbuttonitemstyleplain target:self action:@selector(beginaction:)]; [beginitem settitletextattributes:[nsdictionary dictionarywithobjectsandkeys: [uicolor whitecolor], uitextattributetextcolor,nil] forstate:uicontrolstatenormal]; nsarray *items = [nsarray arraywithobjects:spacer, beginitem, spacer, nil]; [self.navigationcontroller.toolbar setitems:items]; [self.navigationcontroller settoolbarhidden:no];
problem
how go adding uibarbuttonitems toolbar don't show-up when try add them?
i assume it's overriding drawrect
i tried myself custom uitoolbar , problem not -(void)drawrect:(cgcrect)rect
.
i don't know wehere try add buttons on uitoolbar should try add them in -(void)viewdidappear
method of uiviewcontroller class. in way worked me.