ios – 在导航栏下添加进度条

我是iOS开发的新手.

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

我的问题是:

>那个酒吧是进度条吗?
>在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,200,30);
    sendView.backgroundColor = [UIColor clearColor];
    UILabel* lbl = [[UILabel alloc] init];
    lbl.frame = CGRectMake(0,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,pv.frame.size.height);
    pv.progress = progress/100.0;

  [sendView addSubview:pv];
    [self.navigationController.navigationBar addSubview:sendView];

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

解决方法

我在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;
 }

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...