ios中的夜间模式(通知中心)

这个夜间模式不是颜色反转的那种,其实很简单,就是在window上面铺了一层view,把这个view的变成黑色,在调一下透明度就ok了,下面给大家看看代码实现吧
  • 这段代码要在AppDelegate中实现:
- (instancetype)init
{
    self = [super init];
    if (self) {

        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
        [center addObserver:self selector:@selector(receiveNotifica:) name:@"heiyejianglin" object:nil];
        // 白天模式
        NSNotificationCenter *center2 = [NSNotificationCenter defaultCenter];
        [center2 addObserver:self selector:@selector(receiveNotifica2:) name:@"limingjianglin" object:nil];

    }
    return self;
}
- (void)receiveNotifica:(NSNotification *)center
{
    self.nigView.hidden = NO;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"limingjianglinla" object:@"香皂" userInfo: dic];
}
- (void)receiveNotifica2:(NSNotification *)center
{
    self.nigView.hidden = YES;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"heiyejianglinla" object:@"香皂" userInfo: dic];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.nigView = [[UIView alloc] initWithFrame:self.window.bounds];
    self.nigView.userInteractionEnabled = NO;
    self.nigView.hidden = YES;
    self.nigView.backgroundColor = [UIColor blackColor];
    self.nigView.alpha = 0.6;
    [self.window addSubview:self.nigView];
    [_nigView release];

    return YES;
}

- 这段代码要在你加夜间模式中的开关方法中实现

if (button) {
        //        NSLog(@"是");

        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"heiyejianglin" object:@"香皂" userInfo: dic];
    }else {
        //        NSLog(@"否");

        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"limingjianglin" object:@"香皂" userInfo: dic];
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值