0

如何在右侧栏按钮项(CreateNew 按钮)旁边添加活动指示器?

在此处输入图像描述

4

3 回答 3

4

您可以使用的一种方法是使用一些自定义视图初始化 Bar Button。

可以帮助您获得一些提示的最低条码是

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    UIView* aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 40)];
    [aView setBackgroundColor:[UIColor blackColor]];
    [[aView layer] setCornerRadius:8.0f];
    [[aView layer] setBorderColor:[UIColor whiteColor].CGColor];

    UIActivityIndicatorView* loadView  = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    [loadView startAnimating];
    [aView addSubview:loadView];
    [loadView setFrame:CGRectMake(5, 5, 30, 30)];
    [loadView release];

    UIButton* aButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 2, 80, 35)];
    [aButton setImage:[UIImage imageNamed:@"btnLogin.png"] forState:UIControlStateNormal];
    [aView addSubview:aButton];
    [aButton release];


    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:aView];
    [self.navigationItem setRightBarButtonItem:barButton];
    [aView release];
    [barButton release];

}

这是如果您以编程方式执行此操作,否则您也可以使用 nib。以这种方式创建条形按钮将如下所示 -

在此处输入图像描述

[[UIBarButtonItem alloc] initWithCustomView:aView];您可以使用 of方法 寻找更多选项。

希望能帮助到你!!

于 2012-11-22T10:54:31.137 回答
0

您可以使用以下代码添加活动指示器:

    //Create an instance of activity indicator view
    UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];

    //set the initial property
    [activityIndicator stopAnimating];
    [activityIndicator hidesWhenStopped];

    //Create an instance of Bar button item with custome view which is of activity indicator
    UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
    //Set the bar button the navigation bar
    [self navigationItem].rightBarButtonItem = barButton;

    //Memory clean up
    [activityIndicator release];
    [barButton release];

详细代码请参考此链接

于 2012-11-22T10:55:32.380 回答
0

For this try to customize UINavigationController Class.

Add Activity Indicator on navigationBar and control it from your ViewController.

于 2012-11-22T10:52:22.783 回答