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;
}
然后所有的子视图都继承于该视图控制器,主题思想是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;
}
相关文章推荐
- ios开发笔记之 反编译objective-c
- Flash开发iOS应用全攻略(三)——如何使用iOS开发者授权以及如何申请证书
- ios学习:Xcode工具
- 从中美一年来iOS TOP50收入榜变化看2013年游戏风云
- 打印下标iOS 6-字面量
- iOS中定时器NSTimer的使用
- iOS实现在后台播放音乐
- IOS企业管控软件案例
- iOS 7学习:多任务处理之Background Fetch
- 那些年一起用过的iOS开发利器之CocoaPods
- IOS APP 上传到AppStore
- IOS代码管控APP页面横竖屏切换
- Block in iOS (1)
- iOS 基础学习(6)----隐藏状态栏(电池栏)
- IOS网络操作框架----AFNetworking
- iOS之UITableView的使用——处理选中单元格
- IOS 线程处理 子线程
- iOS开发常用的RGB色值
- ios开发UI篇—Kvc简单介绍
- ios旋转问题