本文实例为大家分享了iOS主题皮肤切换代码,供大家参考,具体内容如下
1. 主题皮肤功能切换介绍
主题切换就是根据用户设置不同的主题,来动态改变用户的界面,通常会改变navigationBar背景图片、tabBar背景图片、tabBar中的按钮的图片和选中的背景图片、navigationItem.title 标题的字体颜色、UI中其他元素控件
2.项目目录结构及实现效果截图






3. 具体实现步骤
1.将image文件夹(group)和 Skins拖入到项目工程中的资源文件夹中
2.创建BaseViewController
3.配置theme.plist
4.事项项目所需的基本框架供能,并实现主题的tableView功能
5.创建主题管理器:ThemeManager
6.自定义ThemeTabBarItem 控件
7.创建UI工厂: UIFactory
8. 实现tableView中的didSelected事件完成主题切换
9.记录用户选择的主题,以便用户下次启动时是上次设置的主题
1.创建BaseViewController
#import <UIKit/UIKit.h>
@interface BaseViewController : UIViewController
- (void) reloadThemeImage;
@end
#import "BaseViewController.h"
#import "ThemeManager.h"
#import "NotificationMacro.h"
@interface BaseViewController ()
@end
@implementation BaseViewController
- (id) init {
if (self == [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChangedNotfication:) name:kThemeChangedNotification object:nil];
}
[self reloadThemeImage];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self reloadThemeImage];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) themeChangedNotfication:(NSNotification *)notification {
[self reloadThemeImage];
}
- (void) reloadThemeImage {
ThemeManager * themeManager = [ThemeManager sharedThemeManager];
UIImage * navigationBackgroundImage = [themeManager themeImageWithName:@"navigationbar_background.png"];
[self.navigationController.navigationBar setBackgroundImage:navigationBackgroundImage forBarMetrics:UIBarMetricsDefault];
UIImage * tabBarBackgroundImage = [themeManager themeImageWithName:@"tabbar_background.png"];
[self.tabBarController.tabBar setBackgroundImage:tabBarBackgroundImage];
}
@end










