您的位置:首页 > 移动开发 > IOS开发

iOS中NSNotificationCenter…

2013-10-17 13:26 169 查看
原文地址:iOS中NSNotificationCenter实现主题背景更换作者:伤心的小果冻创建一个baseViewController

然后所有的子视图都继承于该视图控制器,主题思想是baseViewController的背景颜色改变后,所有的子视图控制器的背景颜色也随之改变

在想修改主题背景的地方加入以下代码

[[NSNotificationCenter
defaultCenter]
postNotificationName:@"BGCOLOR_CHANGED" object:[UIColor colorWithRed:r
green:g blue:b
alpha:1]];

r,g,b是你修改的颜色的三基色值(可以用slider设置相应的r,g,b值)

然后在baseViewController的init方法中添加以下代码:

[[NSNotificationCenter
defaultCenter]addObserver:self
selector:@selector(setBGColor:) name:@"BGCOLOR_CHANGED" object:nil];

并添加方法

-(void)setBGColor:(NSNotification *)noti
{

UIColor * color = noti.object;

self.view.backgroundColor = color;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: