1弥虐、創(chuàng)建單利類
.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;
}
創(chuàng)建單利類用于控制全局界面
2货矮、在Switch 點(diǎn)擊事件中設(shè)置單利style的屬性賦值
//創(chuàng)建單利對(duì)象
SingleDayOrNight *single = [SingleDayOrNight shareSingle];
//判斷 開(kāi)關(guān)狀態(tài)? 打開(kāi)的時(shí)候變成黑色? 關(guān)閉變成白色
if (self.mySwitch.on) {
single.style = YES;
self.view.backgroundColor = [UIColor blackColor];
}
else{
single.style = NO;
self.view.backgroundColor = [UIColor whiteColor];
}
3责蝠、在其他頁(yè)面中通過(guò)判斷單利類BOOL屬性style的值區(qū)分背景色
SingleDayOrNight *single = [SingleDayOrNight shareSingle];
if (single.style) {
self.view.backgroundColor = [UIColor blackColor];
}else{
self.view .backgroundColor = [UIColor whiteColor];
}