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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/iOS/330933.html

猜你在找的iOS相关文章