我想知道Apple如何在标题上方实现包含活动指示符的UINavigationItem(参见下图)。 Apple的私有API是否允许这样做?如果没有,如何在应用程序中复制。
谢谢!
答案 0 :(得分:6)
我使用此代码得到了完全相同的渲染:
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。