在导航栏下添加进度条

jus*_* ME 6 uinavigationbar uiprogressview ios

我是iOS开发的新手.

我想知道在iOS 7中发送消息时UINavigationBar是否有一个名为"发送"的标题,有一个进度条正在加载,直到消息成功发送.

我的问题是:

  1. 这个酒吧是进度条吗?

  2. 在iOS 6中,进度条位于UINavigationBar

有人可以给我一些关于如何在iOS 7和iOS6上创建它的想法吗?

我还没有尝试过任何东西.我想阅读一些有关此类问题的教程或示例.

这是我的代码:

int progress = 50;

    CGRect navframe = [[self.navigationController navigationBar] frame];
    int height= navframe.size.height;
    sendView = [[UIView alloc] init];
    sendView.frame = CGRectMake(0, 0, 200, 30);
    sendView.backgroundColor = [UIColor clearColor];
    UILabel* lbl = [[UILabel alloc] init];
    lbl.frame = CGRectMake(0,0, 200, 15);
    lbl.backgroundColor = [UIColor clearColor];
    lbl.textColor = [UIColor whiteColor];
    lbl.shadowColor = [UIColor colorWithWhite:0 alpha:0.3];
    lbl.shadowOffset = CGSizeMake(0, -1);
    lbl.font = [UIFont boldSystemFontOfSize:12];
    lbl.text = @"";
    lbl.textAlignment = UITextAlignmentCenter;
    [sendView addSubview:lbl];
    UIProgressView* pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
    pv.frame = CGRectMake(0, 30-pv.frame.size.height, 200, pv.frame.size.height);
    pv.progress = progress/100.0;

  [sendView addSubview:pv];
    [self.navigationController.navigationBar addSubview:sendView];
Run Code Online (Sandbox Code Playgroud)

不幸的是,进度条不在navigationController下.为什么?

Dav*_*d H 12

我在我的iOS应用程序中所做的是创建并添加UIProgressBar作为导航栏的子视图,告诉它[progressBar setTranslatesAutoresizingMaskIntoConstraints:NO],并添加约束以将其左右固定到条形图,并将其底部固定到导航栏的底部.导航控制器为其维护一个ivar,并提供显示/隐藏它的公共方法,并设置其值.看起来就像Safari中的内容下载一样.

编辑:这是创建并添加到导航栏的代码:

// in UINavigationController subclass
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    UIProgressView *progress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
    progress.tag = DISPLAY_PROGRESS_VIEW;
    [self.view addSubview:progress];
    UINavigationBar *navBar = [self navigationBar];

    NSLayoutConstraint *constraint;
    constraint = [NSLayoutConstraint constraintWithItem:progress attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:navBar attribute:NSLayoutAttributeBottom multiplier:1 constant:-0.5];
    [self.view addConstraint:constraint];

    constraint = [NSLayoutConstraint constraintWithItem:progress attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:navBar attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
    [self.view addConstraint:constraint];

    constraint = [NSLayoutConstraint constraintWithItem:progress attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:navBar attribute:NSLayoutAttributeRight multiplier:1 constant:0];
    [self.view addConstraint:constraint];

    [progress setTranslatesAutoresizingMaskIntoConstraints:NO];
    progress.hidden = YES;
 }
Run Code Online (Sandbox Code Playgroud)