iOS7 when UIsearchbar added in UINavigationBar not showing cancel button -
i add uisearchbar above uinavigationbar , set uisearchbar showscancelbutton yes, work fine in ios6 in ios7 not showing cancel button. used below code snippet
uisearchbar *searchbar = [[uisearchbar alloc] initwithframe:cgrectmake(0, 0, 600, 44)]; searchbar.showscancelbutton = yes; searchbar.translucent = no; [searchbar settintcolor:[uicolor redcolor]]; searchbar.backgroundcolor = [uicolor yellowcolor]; [self.navigationcontroller.navigationbar addsubview:searchbar];
for reason ios7 not show cancel button when added navigation bar. happens if try setting titleview of navigationitem.
you can circumvent problem wrapping uisearchbar in uiview first. here's how titleview:
uisearchbar *searchbar = [uisearchbar new]; searchbar.showscancelbutton = yes; [searchbar sizetofit]; uiview *barwrapper = [[uiview alloc]initwithframe:searchbar.bounds]; [barwrapper addsubview:searchbar]; self.navigationitem.titleview = barwrapper;
Comments
Post a Comment