Objective c 带自定义背景的UINavigationBar-如何使rightBarButton可见
我已经在我的RootViewController中自定义了导航栏的背景(只是代码的一部分) 我按下detailViewController并将活动指示器添加为右按钮项Objective c 带自定义背景的UINavigationBar-如何使rightBarButton可见,objective-c,ios,uinavigationbar,Objective C,Ios,Uinavigationbar,我已经在我的RootViewController中自定义了导航栏的背景(只是代码的一部分) 我按下detailViewController并将活动指示器添加为右按钮项 UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; actInd.activityIndicatorViewStyle = UIActivityIndicatorVi
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];
问题是指示器不可见,但没有自定义背景,它工作正常。按以下方式设置RightBarButtonim self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“退出”样式:uiBarbuttonItems样式普通目标:自我操作:@selector(取消)]
尝试此操作并检查背景的位置使用以下方法设置rightBarButtonItem self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“退出”样式:uiBarbuttonItems样式普通目标:自我操作:@selector(取消)]
尝试此操作,同时检查背景的位置。活动指示灯在那里,只是没有被激活。尝试按如下方式设置动画:
[actInd startAnimating];
actInd.hidesWhenStopped = NO;
或者,如果要使其保持可见,请按如下方式设置hideWhenStopped
属性:
[actInd startAnimating];
actInd.hidesWhenStopped = NO;
活动指示灯在那里,只是没有被激活。尝试按如下方式设置动画:
[actInd startAnimating];
actInd.hidesWhenStopped = NO;
或者,如果要使其保持可见,请按如下方式设置hideWhenStopped
属性:
[actInd startAnimating];
actInd.hidesWhenStopped = NO;
您是否尝试从UIActivityIndicatorView更改原点 或者在UIView中创建它并将此UIView添加到UIBarButtonim
我认为问题可能是元素的帧。是否尝试从UIActivityIndicatorView更改原点 或者在UIView中创建它并将此UIView添加到UIBarButtonim
我认为问题可能是来自元素的帧。我认为您可以更好地更改导航栏背景。创建
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);
}
我这样做了,而且我从来没有对任何按钮添加任何问题:)我认为您可以更好地更改导航栏背景。创建
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);
}
我这样做了,而且我从来没有给任何按钮添加任何问题:)佐利斯的想法是正确的。如果您不使用或不能使用子类,我认为您的问题在于您正在索引0处添加子视图,因此它位于导航栏中其他视图的顶部,它可能隐藏了您的按钮 佐利斯的想法是正确的。如果您不使用或不能使用子类,我认为您的问题在于您正在索引0处添加子视图,因此它位于导航栏中其他视图的顶部,它可能隐藏了您的按钮 通过这种方式,您可以解决问题: 创建活动指示器并添加到视图中1 现在,该视图1在该视图1的帮助下添加或创建导航栏。现在,当view1自动可见时,您将能够看到加载指示器。
试试这个。通过这种方式,您可以解决问题: 创建活动指示器并添加到视图中1 现在,该视图1在该视图1的帮助下添加或创建导航栏。现在,当view1自动可见时,您将能够看到加载指示器。
试试这个。谢谢你的回复,但我先检查了一下。你使用的是UINavigationController吗?我们可以看看你是如何创建自定义背景的吗?谢谢你的回复,但我先检查了一下。你使用的是UINavigationController吗?我们可以看到您是如何创建自定义背景的吗?activityIndicator属性是否保留指示器?如何将活动指示器添加为右栏按钮项?activityIndicator属性是否保留指示器?如何将活动指示器添加为右栏按钮项?