如何在 iphone/ipod 状态栏添加图标?

发布于 2024-11-14 23:07:45 字数 573 浏览 4 评论 0原文

苹果不允许开发者在状态栏中添加图标吗?

我按照书上的代码进行操作。代码很简单:

@interface UIApplication (extended) 
- (void) addStatusBarImageNamed:(NSString *)aName; 
- (void) removeStatusBarImageNamed:(NSString *)aName; 

@end 

- (void)performAction{
    if (xxx) {
        [[UIApplication sharedApplication]addStatusBarImageNamed:@"Default_EN.png"];
    }
    else {
        [[UIApplication sharedApplication]addStatusBarImageNamed:@"Default_EC.png"];

    }
}

但它给出了以下反馈:

-addStatusBarImageNamed:已弃用。什么也不做。

我能做些什么?

Does Apple not allow developers to add an icon into a status bar?

I followed code from a book. The code is simple:

@interface UIApplication (extended) 
- (void) addStatusBarImageNamed:(NSString *)aName; 
- (void) removeStatusBarImageNamed:(NSString *)aName; 

@end 

- (void)performAction{
    if (xxx) {
        [[UIApplication sharedApplication]addStatusBarImageNamed:@"Default_EN.png"];
    }
    else {
        [[UIApplication sharedApplication]addStatusBarImageNamed:@"Default_EC.png"];

    }
}

But it gives the following feedback :

-addStatusBarImageNamed: is deprecated. Doing nothing.

What can I do?

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

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

发布评论

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

评论(2

℡寂寞咖啡 2024-11-21 23:07:45

据我所知,SDK 中不允许这样做,但他们可能有一些私有 API 来执行此操作,但到目前为止他们还没有公开这些,我认为你无法在状态栏中添加图标。 如果有人知道请纠正我。

To my best knowledge, this isn't permitted within the SDK, but there could be the possibilities that they could have some private API to do so but so far they haven't exposed those, I think you are'nt able to add icon in status bar. If someone know please correct me .

又怨 2024-11-21 23:07:45

Classes/YourViewController.m 中,需要用此覆盖 addStatusBarImageNamed:removeOnExit: 方法。

- (void) addStatusBarImageNamed:(NSString*)image removeOnExit: (BOOL) remove {
if(_statusbarimage!=nil && _responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[self removeStatusBarImageNamed:_statusbarimage];
statusbarimage=image;
}
if (_responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[super addStatusBarImageNamed:image removeOnExit: remove];
}
}  

看看它是否工作正常。

In Classes/YourViewController.m, the addStatusBarImageNamed:removeOnExit: method needs to be overwritten with this.

- (void) addStatusBarImageNamed:(NSString*)image removeOnExit: (BOOL) remove {
if(_statusbarimage!=nil && _responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[self removeStatusBarImageNamed:_statusbarimage];
statusbarimage=image;
}
if (_responds) {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"statusBarEnabled"] integerValue] == 1)
[super addStatusBarImageNamed:image removeOnExit: remove];
}
}  

See if it works fine.

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