在导航栏下添加进度条 [英] adding progress bar under navigation bar

查看:231
本文介绍了在导航栏下添加进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS开发的新手。

I am new to iOS development.

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

I would like to know if in iOS 7 when sending a message under UINavigationBar, which has a title called : Sending, there is a progress bar that is loading till the message is successfully sent.

我的问题是:


  1. 该栏是否为进度条?

  1. Is that bar a progress bar?

在iOS 6中,进度条位于<$ c $内C> UINavigationBar的?

In iOS 6, the progress bar is inside the UINavigationBar?

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

Can someone give me some ideas about how to create this on iOS 7 and iOS6?

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

I haven't yet tried anything. I would like to read some tutorials or examples with this type of issue.

这是我的代码:

int progress = 50;

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

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

Unfortunalty the progress bar is not under the navigationController. Why?

推荐答案

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

What I'm doing in my iOS app is to create and add a UIProgressBar as a subview of the Navigation bar, telling it [progressBar setTranslatesAutoresizingMaskIntoConstraints:NO], and adding constraints to pin it left and right to the bar, and its bottom to the bottom of the navigation bar. The navigation controller maintains an ivar to it, and offers public methods to show/hide it, and to set its value. Looks just like the one in Safari as content downloads.

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

here is the code to create and add it to the nav bar:

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

这篇关于在导航栏下添加进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆