gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:36:33 26 4
gpt4 key购买 nike

我是 iOS 开发新手。

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

我的问题是:

  1. 那个条是进度条吗?

  2. 在 iOS 6 中,进度条在 UINavigationBar 中?

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

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

这是我的代码:

int 进度=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 下。为什么?

最佳答案

我在我的 iOS 应用程序中所做的是创建并添加一个 UIProgressBar 作为导航栏的 subview ,告诉它 [progressBar setTranslatesAutoresizingMaskIntoConstraints:NO],并添加约束以将其固定在左侧和右边的栏,它的底部到导航栏的底部。导航 Controller 为它维护一个 ivar,并提供公共(public)方法来显示/隐藏它,并设置它的值。看起来就像 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;
}

关于ios - 在导航栏下添加进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20100475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com