为什么导航栏中未显示uiactivity指示符

时间:2017-07-30 10:56:09

标签: ios objective-c uiactivityviewcontroller

UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 14, 14)];
[activityView sizeToFit];
[activityView setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin)];

activityView.hidesWhenStopped = NO;

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:activityView];

[activityView startAnimating];

右上角没有显示uiactivity指示器的原因是什么?右上方的导航栏中没有显示任何内容。

2 个答案:

答案 0 :(得分:1)

因为您没有指定活动指标的颜色 分配颜色然后我将在导航栏中显示

activityView.color = [UIColor blackColor];

答案 1 :(得分:1)

您需要设置活动指标的类型...试试这个:

UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(0, 0, 14, 14);
[activityView sizeToFit];
[activityView setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin)];

activityView.hidesWhenStopped = NO;

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:activityView];

[activityView startAnimating];