带有提示和活动指示器的 UINavigationItem

发布于 2024-08-21 17:13:00 字数 301 浏览 3 评论 0原文

我想知道 Apple 如何实现包含活动指示器的 UINavigationItem(请参见下面的附图),位于标题上方。 Apple 的私有 API 允许这样做吗?如果没有,如何在应用程序中重现它。

带有提示和活动指示器的 UINavigationItem http://img218.imageshack.us/img218/8819/ img0133g.png

谢谢!

I'm wondering how Apple implemented the UINavigationItem that contains an activity indicator (see attached image below), above the title. Is this Apple's private API that allows to do that? If not, how can it be reproduced in an application.

UINavigationItem with prompt and activity indicator http://img218.imageshack.us/img218/8819/img0133g.png

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2024-08-28 17:13:00

我使用以下代码得到了与您的屏幕截图完全相同的渲染:

 UIView                      *viewContainingSpinner;
    UIActivityIndicatorView     *activityIndicatorView;
    UIBarButtonItem             *activityButtonItem;
    UIBarButtonItem             *rightBarButtonItem;


    // Configuring the title and the prompt title of the navigation bar
    [self.navigationItem setTitle:@"MobileMe"];
    [self.navigationItem setPrompt:@"Vérification du compte MobileMe"];

    // We will create a UIBarButtonItem that has a custom view (viewContainingSpinner).
    // A subview of viewContainingSpinner will be a UIActivityIndicatorView (activityIndicatorView)
    // We need to have this "intermediate" view to position the spinner at the right position (the UIBarButtonItem ignores the origin and height of its custom view)
    viewContainingSpinner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 85)];
    activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    [viewContainingSpinner addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    [activityIndicatorView release];

    activityButtonItem = [[UIBarButtonItem alloc] initWithCustomView:viewContainingSpinner];
    self.navigationItem.leftBarButtonItem = activityButtonItem;
    [viewContainingSpinner release];
    [activityButtonItem release];

    // Finally, configuring the right button
    rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Enregistrer" style:UIBarButtonItemStylePlain target:nil action:nil];
    [rightBarButtonItem setEnabled:NO];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    [rightBarButtonItem release];

PS:在实际应用程序中,我建议不要在代码中使用本地化字符串。 “Vérification”一词的 é 可能会给您带来麻烦。
看看方法 NSLocalizedString

I got the exact same rendering than your screenshot with this code:

 UIView                      *viewContainingSpinner;
    UIActivityIndicatorView     *activityIndicatorView;
    UIBarButtonItem             *activityButtonItem;
    UIBarButtonItem             *rightBarButtonItem;


    // Configuring the title and the prompt title of the navigation bar
    [self.navigationItem setTitle:@"MobileMe"];
    [self.navigationItem setPrompt:@"Vérification du compte MobileMe"];

    // We will create a UIBarButtonItem that has a custom view (viewContainingSpinner).
    // A subview of viewContainingSpinner will be a UIActivityIndicatorView (activityIndicatorView)
    // We need to have this "intermediate" view to position the spinner at the right position (the UIBarButtonItem ignores the origin and height of its custom view)
    viewContainingSpinner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 85)];
    activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    [viewContainingSpinner addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    [activityIndicatorView release];

    activityButtonItem = [[UIBarButtonItem alloc] initWithCustomView:viewContainingSpinner];
    self.navigationItem.leftBarButtonItem = activityButtonItem;
    [viewContainingSpinner release];
    [activityButtonItem release];

    // Finally, configuring the right button
    rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Enregistrer" style:UIBarButtonItemStylePlain target:nil action:nil];
    [rightBarButtonItem setEnabled:NO];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    [rightBarButtonItem release];

PS: In a real application, I would advise against having a localized string in code. The é of the word "Vérification" could cause you trouble.
Have a look at the method NSLocalizedString.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文