ios切换主题demo分析
来源:互联网 发布:拍照答题软件下载 编辑:程序博客网 时间:2024/06/08 16:01
代码出处cocoachina
必须包含文件是HPThemeManager.h和HPThemeManager.m
再HPThemeManager.h里申明一个主题的字典,主题索引和当前主题
NSDictionary *themeDictionary; NSInteger currentThemeIndex; NSString *currentTheme;在HPThemeManager.m里初始化主题
-(id)init{ self = [super init]; if(self) { NSString *path = [[NSBundle mainBundle] pathForResource:@"themes" ofType:@"plist"]; themeDictionary = [[NSDictionary alloc] initWithContentsOfFile:path]; self.currentThemeIndex = 0; self.currentTheme = @"maroon"; //default theme } return self;}在resourece文件夹里添加了名为themes的plist文件,里面存放主题名。
设置初始主题为maroon
每次加载主题的素材时都从目录加载
-(void)updateTheme:(NSNotification*)notif{ NSString *themename = [HPThemeManager sharedThemeManager].currentTheme; NSString *themePathTmp = [[[HPThemeManager sharedThemeManager] themeDictionary] objectForKey:themename]; NSString *themePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:themePathTmp]; if(themePath){ settingTable.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:[themePath stringByAppendingPathComponent:@"background.png"]]]; [backButton setImage:[UIImage imageWithContentsOfFile:[themePath stringByAppendingPathComponent:@"back.png"]] forState:UIControlStateNormal]; navback.image = [UIImage imageWithContentsOfFile:[themePath stringByAppendingPathComponent:@"nav.png"]]; } NSLog(@"%@",themePath);}
在选择主题的tableview中加如下代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *selectName = [themes objectAtIndex:indexPath.row]; [[HPThemeManager sharedThemeManager] setCurrentTheme:selectName]; //must set before post [[HPThemeManager sharedThemeManager] setCurrentThemeIndex:indexPath.row]; [[NSNotificationCenter defaultCenter] postNotificationName:kThemeDidChangeNotification object:nil userInfo:[NSDictionary dictionaryWithObject:selectName forKey:@"selectedTheme"]]; //[tableView deselectRowAtIndexPath:indexPath animated:YES];}
在放入主题素材的文件夹时一定要将整个文件夹加入
demo下载:http://download.csdn.net/detail/gwh111/5067279
- ios切换主题demo分析
- Android 切换主题demo
- 主题分析DEMO
- IOS主题切换ThemeManager
- iOS实现主题切换技术点之一
- iOS 中如何实现 App 主题切换
- 切换主题
- 主题切换
- iOS开发之App主题切换完整解决方案(Swift版)
- iOS开发之App主题切换完整解决方案(Swift版)
- iOS开发之App主题切换完整解决方案(Swift版)
- iOS开发之App主题切换完整解决方案(Swift版)
- iOS开发之App主题切换完整解决方案(Swift版)
- iOS开发之App主题切换完整解决方案(Swift版)
- iOS开发之App主题切换完整解决方案(Swift版)
- 源码推荐:仿写映客直播 iOS快速切换主题等
- Theme切换(主题切换)
- Ext 主题切换
- 最讨厌那些分了手,还无耻的说想念的人
- udev、热插拔和驱动模块加载
- 数据库范式
- Validation failed for one or more entities
- android应用程序安装位置分析
- ios切换主题demo分析
- 无题
- 2012年终总结-辞旧迎新
- hibernate jpa 注解 @Temporal(TemporalType.DATE) 格式化时间日期,页面直接得到格式化类型的值
- leetcode 76: Reverse Linked List II
- 全球云应用趋势
- SCSI IDE
- BIT1044 A^B mod C
- The run destination My Mac 64-bit is not valid for Running the scheme '*****'.