[英]UINavigationBar with customized background - how to make rightBarButton visible
我已經在RootViewController中自定義了導航欄的背景(只是代碼的一部分)
[navBar insertSubview:customBack atIndex:0];
我推送detailViewController並將活動指示器添加為rightBarButtonItem
UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
self.activityIndicator = actInd;
[actInd release];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:self.activityIndicator];
[self.navigationItem setRightBarButtonItem:barButton];
[barButton release];
問題是該指示器不可見,但沒有自定義背景,則可以正常工作。
我認為您可以更好地更改您的navigationBar背景。 創建UINavigationBar
的子類並添加:
- (void)drawRect:(CGRect)rect {
UIImage * image = [UIImage imageNamed:@"MyNavigationBarBackground.png"];
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextScaleCTM(ctx, 1.0, -1.0); // Otherwise the image is drawn upside-down
CGContextDrawTiledImage(ctx, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
}
我這樣做,我從來沒有添加任何按鈕的問題:)
Zoleas有正確的想法。 如果您不使用或不能使用子類,我想您的問題是您要在索引0處添加子視圖,因此該子視圖位於導航欄中其他視圖的頂部,這可能是隱藏了按鈕。
通過以下方式設置rightBarButtonItem
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@“退出”樣式:UIBarButtonItemStylePlain目標:自我操作:@selector(cancel)];
試試這個,並檢查背景的位置
活動指示器只是在那里沒有被激活。 嘗試像這樣制作動畫:
[actInd startAnimating];
或者,如果要使其可見,請設置hideWhenStopped
屬性,如下所示:
actInd.hidesWhenStopped = NO;
您是否嘗試過從UIActivityIndicatorView更改原點?
或在UIView中創建它,並將此UIView添加到UIBarButtonItem。
我認為問題可能出在元素的框架上。
通過這種方式,您可以解決問題:創建活動指示器並添加到view1中現在,此view1借助此view1添加或創建導航欄。 現在,當view1自動可見時,您將能夠看到加載指示器。 只是瘋狂嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.