1、创建单利类
.h文件
@property(nonatomic,assign)BOOL style;
+(SingleDayOrNight *)shareSingle;
.m文件
+(SingleDayOrNight *)shareSingle{
static SingleDayOrNight *single = nil;
@synchronized(self) {
if (single ==nil) {
single = [[SingleDayOrNight alloc]init];
}
}
return single;
}
创建单利类用于控制全局界面
2、在Switch 点击事件中设置单利style的属性赋值
//创建单利对象
SingleDayOrNight *single = [SingleDayOrNight shareSingle];
//判断 开关状态 打开的时候变成黑色 关闭变成白色
if (self.mySwitch.on) {
single.style = YES;
self.view.backgroundColor = [UIColor blackColor];
}
else{
single.style = NO;
self.view.backgroundColor = [UIColor whiteColor];
}
3、在其他页面中通过判断单利类BOOL属性style的值区分背景色
SingleDayOrNight *single = [SingleDayOrNight shareSingle];
if (single.style) {
self.view.backgroundColor = [UIColor blackColor];
}else{
self.view .backgroundColor = [UIColor whiteColor];
}
网友评论