微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/iOS/330933.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐