带有提示和活动指示符的UINavigationItem [英] UINavigationItem with prompt and activity indicator

查看:146
本文介绍了带有提示和活动指示符的UINavigationItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Apple如何在标题上方实现包含活动指示符的UINavigationItem(参见下图)。 Apple的私有API是否允许这样做?如果没有,如何在申请中复制。

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 http://img218.imageshack.us/img218/8819/img0133g.png

谢谢!

推荐答案

我使用此代码得到了完全相同的渲染:

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:在实际应用中,我会建议不要在代码中有一个本地化的字符串Vérification这个词的é可能会给你带来麻烦。
查看方法 NSLocalizedString

这篇关于带有提示和活动指示符的UINavigationItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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