在Navigationbar中显示progressIndicator

时间:2013-06-24 02:31:59

标签: iphone navigationbar

当我点击按钮(刷新)时,我想在NavigationBar中显示一个循环进度指示器代替标题,当刷新成功时,指示消失,标题将再次显示。

有什么建议吗?谢谢。

1 个答案:

答案 0 :(得分:0)

您可以编写将UIActivityIndi​​catorView添加到UInavigatiobar中的代码,如: -

 UIView *activityView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
 activityView.backgroundColor = [UIColor clearColor];
 UIActivityIndicatorView *act =[[UIActivityIndicatorView alloc] init]; //create this globule so u can stop it while your progress finished
 act.frame=CGRectMake(0, 0, 30, 30);
 [activityView addSubview:act];
 self.navigationItem.titleView = activityView;

注意: - [act startAnimating];[act stopAnimating];符合您的需要

或者您可以将其添加到UInavigation BarbuttonItem

    UIView *activityView = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
    UIActivityIndicatorView *act =[[UIActivityIndicatorView alloc] init];
    act.frame=CGRectMake(0, 0, 30, 30);
    UIBarButtonItem *actItem = [[[UIBarButtonItem alloc] initWithCustomView:activityView] autorelease];
    [activityView addSubview:act];
    self.navigationItem.rightBarButtonItem = actItem;

注意: - [UIActivityIndicatorView startAnimating];[UIActivityIndicatorView stopAnimating];符合您的需要