Git Product home page Git Product logo

leetheme's Introduction

LEETheme - 最好用的轻量级主题管理框架

            Build Status 

演示

新日间Demo演示 新夜间Demo演示

新日间Demo演示 新夜间Demo演示

特性

  • 链式语法 结构优雅
  • 两种设置模式,可根据对象单独添加某一主题中某一属性或方法的设置,可使用标识符模式为某一属性或方法设置标识符,二者可混合使用,满足不同需求的开发者。
  • 轻量级设计, 简化文件架构, 全部集合为两个文件中。
  • 支持对所有NSObject子类对象进行设置, 并提供了常用视图对象的颜色和图片等属性的快捷设置方法。
  • 支持自定义类型对象的自定义属性或方法设置。
  • 支持动态添加主题,可实现类似网络主题下载并切换的功能。
  • 语法优雅, 高效简洁, OC链式, 一行代码完成对象设置。
  • 当前主题记忆功能, 下一次启动自动布置。
  • 完善的文档注释和使用教程, 并有众多Demo可供参考。

用法

默认模式

主要适用于固定主题样式的情况下使用

优点:直观 清晰, 编码时可随初始化控件编写完成, 不影响编码思路.

缺点:每个主题的设置固定, 不支持新主题的设置.

// 添加背景颜色
imageView.lee_theme
.LeeAddBackgroundColor(@"red" , [UIColor redColor])
.LeeAddBackgroundColor(@"blue" , [UIColor blueColor]);

// 添加图片
imageView.lee_theme
.LeeAddImage(@"red" , [UIImage imageNamed:@"red.png"])
.LeeAddImage(@"blue" , [UIImage imageNamed:@"blue.png"]);

// 添加自定义设置 (每个主题标签对应一个block , 当触发其中添加的主题后会执行相应的block)
imageView.lee_theme
.LeeAddCustomConfig(@"red" , ^(UIImageView *item){
    
    item.hidden = YES; //简单举例 红色主题启动时 将这个imageview对象隐藏
})
.LeeAddCustomConfig(@"blue" , ^(UIImageView *item){
    
    item.hidden = NO; //或者随便做一些其他羞羞的事
});

LEETheme支持对任何NSObject子类的对象进行其持有属性或方法的设置 , 例如UIImageView类的对象持有image属性 , 那么使用LEETheme就可以为它设置不同主题对应的image属性值, 以此类推 , 当然所有类型的对象都可以添加自定义Block设置.

标识符模式

适用于固定和动态主题样式的情况下使用

优点:对于对象的设置只需要给定标识符即可, 代码较默认模式更加简洁, 可动态增加新主题JSON配置.

JSON标准格式
{
	"color": {
	   	"identifier1(唯一标识符)": "十六进制颜色值",
	    	"identifier2": "#000000"
	},
	"image": {
		"identifier3(唯一标识符)": "图片名称",
		 "identifier4": "lee.png"
	},
	"other": {
		"identifier5(唯一标识符)": "其他值",
		 "identifier6": "12345"
	}
}

这里一般分为3种类型

  1. 颜色类型 (color) - 适用于颜色属性
  2. 图片类型 (image) - 适用于图片属性
  3. 其他类型 (other) - 适用于自定义Block

JSON配置关系图

添加新主题的JSON配置
/**
 * 添加json , 设置所属主题标签 , 设置资源路径  所添加过的Json配置会自动存储 无需每次都添加
 * 关于资源路径的设置 只需要传入documents目录后的路径即可 如:@"theme_resources/black"
 */
 [LEETheme addThemeConfigWithJson:json Tag:@"red" ResourcesPath:nil];
移除某一主题的JSON配置
// 所要移除的主题标签
[LEETheme removeThemeConfigWithTag:@"red"];
对象设置
// 设置背景颜色
imageView.lee_theme.LeeConfigBackgroundColor(@"identifier2");

// 设置图片
imageView.lee_theme.LeeConfigImage(@"identifier4");

// 自定义设置 (如果没有对应的标识符 则不会触发该block执行 , 如果有 则执行)
imageView.lee_theme.LeeCustomConfig(@"identifier6" , ^(id item , id value){
		
	//item 为当前对象
	//value 为当前主题的JSON配置中 other 类型下 "identifier6"对应的值
	item.alpha = [value floatValue]; //举个例子 设置一下透明度
});

启用主题

启用主题后 , LEETheme会自动保存当前所启用的主题 , APP下一次开启会自动启用上一次的主题.

// 启用主题
[LEETheme startTheme:@"主题标签"];

建议在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中添加默认主题的设置 , 指定第一次启动APP时默认启用的主题.

// 设置默认主题
[LEETheme defaultTheme:@"主题标签"];

关于添加过渡动画效果

这里提供一个小技巧 可以让过渡更加自然 可根据自身情况调整使用. 切换主题前 获取当前window的快照视图 并覆盖到window上 > 执行主题切换 > 将覆盖的快照视图通过动画隐藏 显示出切换完成的真实window.

// 覆盖截图
UIView *tempView = [weakSelf.window snapshotViewAfterScreenUpdates:NO];
[weakSelf.window addSubview:tempView];

// 切换主题
[LEETheme startTheme:@"tag"];

// 增加动画 移除覆盖
[UIView animateWithDuration:1.0f animations:^{
            
	tempView.alpha = 0.0f;
            
} completion:^(BOOL finished) {
            
	[tempView removeFromSuperview];
}];

注意事项

  • 默认模式与标识符模式可以同时使用.
  • 当一个对象同时使用了2种设置模式 那么同主题情况下会优先使用后设置的.
  • JSON中的标识符(identifier)要确保在当前JSON中是唯一的.
  • 每个主题对应的JSON中 标识符(identifier)要相同.
  • 不要忘记设置默认主题, 应用中应该最少会有一个默认的主题.

更多示例Demo

新闻资讯详情Demo

安装

CocoaPods

  1. 将 cocoapods 更新至最新版本.
  2. 在 Podfile 中添加 pod 'LEETheme'
  3. 执行 pod installpod update
  4. 导入 <LEETheme/LEETheme.h>

手动安装

  1. 下载 LEETheme 文件夹内的所有内容。
  2. 将 LEETheme 内的源文件添加(拖放)到你的工程。
  3. 导入 LEETheme.h

系统要求

该库最低支持 iOS 7.0Xcode 9.0

版本更新

详情请查看更新日志

许可证

LEETheme 使用 MIT 许可证,详情见 LICENSE 文件。

友情链接

高效的自动布局库 - SDAutoLayout

个人主页

我的简书

leetheme's People

Contributors

lixiang1994 avatar zpp506 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leetheme's Issues

使用这个库之后,会不定时的Crash

新建的测试项目,导入这个库文件之后,我只是在delegate中设置了默认主题([LEETheme defaultTheme:DAY];)
然后添加了Demo中 LEEBubble 相关的代码,什么都不做,过段时间应用就crash掉了,重现了4、5次。

请问导航栏的背景图片该如何更换?

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar_background_image"]
forBarMetrics:UIBarMetricsDefault];
类似这种方式 独立模式或者JSON模式下该如何更换背景图片?

[self lee_theme_dealloc] EXC_BAD_ACCESS crash

在APP从后台切换到前台时,可能会造成app crash,通过异常断点查看,崩溃到的[self lee_theme_dealloc];这里,不太理解作者为什么在这里要多次递归调用该方法,可能引起crash的原因就是self(LEETheme)对象过度内存释放导致的,希望作者能修复该问题。谢谢。

下面是出现crash的文件,及代码片段:

文件:#import "LEETheme.h"

...

@implementation NSObject (LEEThemeConfigObject)
...

- (void)lee_theme_dealloc{
    
    if ([self isLeeTheme]) {
        
        [[NSNotificationCenter defaultCenter] removeObserver:self name:LEEThemeChangingNotificaiton object:nil];
        
        objc_removeAssociatedObjects(self);
    }
    [self lee_theme_dealloc];  // 注:crash 在这里
}

关于开源协议

hi, 你好:
这个软件使用的是GPL V3开源协议,那么问题来了,使用你这个开源库的用户,他们必须将自己的软件也开源。这个对于一些小公司或者个人来说,可能不是很合适。

我的意思是,如果使用了你的代码库的个人或者公司,想对你的代码做一定的定制,那么必须将自己的软件也开源。

pod

pod 'LEETheme', '~> 1.1.8' 下载下来的是1.1.7版本, 还有 return weakSelf.LeeAddKeyPathAndValue(tag , @"_placeholderLabel.textColor" , color); 程序运行会在这个地方崩溃是什么原因??

这种换肤、主题切换个人觉得有些问题

image
这种设置方式,代码不会报错,但是运行会崩溃,看了下源码,所有属性其实都在LEEThemeConfigModel里面,也就是说任意NSObject对象都能调用,没有做限制区分

iOS8.4 要崩溃

NSObject (LEEThemeConfigObject)交换方法的时候有问题,lee_dealloc根本没有交换到NSObject里面的方法,而是某个子类的dealloc,实际情况其实是lee_dealloc根本从来就没执行,通知永远没有被移除,在iOS8.4上如果有重用Cell的情况会崩溃。将交换的class改成NSObject就好了。

颜色在json里面怎么办,demo是直接写的颜色

    tabBarItem.lee_theme
    .LeeAddSelectorAndValues(DAY , @selector(setTitleTextAttributes:forState:) , @{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:LEEColorRGB(33, 151, 216)} , @(UIControlStateSelected) , nil)
    .LeeAddSelectorAndValues(NIGHT , @selector(setTitleTextAttributes:forState:) , @{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:LEEColorRGB(28, 125, 178)} , @(UIControlStateSelected) , nil)
    .LeeAddSelectorAndValues(DAY , @selector(setTitleTextAttributes:forState:) , @{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:LEEColorRGB(159, 159, 159)} , @(UIControlStateNormal) , nil)
    .LeeAddSelectorAndValues(NIGHT , @selector(setTitleTextAttributes:forState:) , @{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:LEEColorRGB(230, 230, 230)} , @(UIControlStateNormal) , nil);

self.navigationController.navigationBar.lee_theme 不能立即生效,

@interface NewHotLineViewController : WMPageController h文件

以下是m文件 更改theme以后,下面的设置不能立即生效,需要左右滑动几次才能生效
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];

self.navigationController.navigationBar.lee_theme
.LeeAddCustomConfig(DAY , ^(UINavigationBar *item){
    [item setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault];
    item.barStyle = UIBarStyleDefault;
})
.LeeAddCustomConfig(NIGHT , ^(UINavigationBar *item){
    [item setBackgroundImage:[UIImage imageWithColor:RGBColor(55, 55, 55)] forBarMetrics:UIBarMetricsDefault];
    item.barStyle = UIBarStyleBlack;
});

Logo Design Offer as Open Source Contribution

Hello Sir. I'm a Graphics Designer. I'm happy to see an open source project, So, I want provide a logo for you. Would you mind if I propose a new logo design for your project as my Open Source Contribution?

Thanks for your attention.

高频调用 LeeConfigImage 的性能问题

  • (id)getValueWithTag:(NSString *)tag Identifier:(NSString *)identifier 这个方法中,获取 Image 是否可以加缓存?
    高频调用的时候每次都要读文件,非常耗费性能。

请问使用json配置方式和直接用颜色配置的差异大么?

我试着用了两种方式来配置主题,发现json方式真的很简洁,而且使用起来也更方便
就是不知道两者的性能如何,反正我用肉眼没有感受到差异,除了代码量上

#pragma mark - * * * * * Json主题配置方式 * * * * *

#define kAppTheme1              @"Theme1" // 主题一:
#define kAppTheme2              @"Theme2" // 主题二:
#define kAppTheme3              @"Theme3" // 主题三:

#define kThemeIdent1            @"ident1" // 主题标志符1(通用主题色)
#define kThemeIdent2            @"ident2" // 主题标志符2 (背景颜色)
#define kThemeIdent3            @"ident3" // 主题标志符3 (个人中心背景图片)
//#define kThemeIdent4            @"ident4" // 主题标志符4 ()

// KVC颜色快速设置(由于这里几乎只用到主题颜色,所以Identifier写死为kThemeIdent1)
#define kThemeKVCColor(view, key)       view.lee_theme.LeeConfigKeyPathAndIdentifier(key, kThemeIdent1)
// 文本颜色快速设置 - 传入带有.textColor属性的视图,如:UILabel、UITextView、UITextField等
#define kThemeTextColor(view)           view.lee_theme.LeeConfigTextColor(kThemeIdent1);
// 背景颜色快速设置
#define kThemeBackgroundColor(view)     view.lee_theme.LeeConfigBackgroundColor(kThemeIdent1);
// TintColor颜色快速设置
#define kThemeTintColor(view)           view.lee_theme.LeeConfigTintColor(kThemeIdent1);
// BarTintColor颜色快速设置
#define kThemeBarTintColor(view)        view.lee_theme.LeeConfigBarTintColor(kThemeIdent1);

跟随系统主题有点问题

当我APP是浅色的时候,我去显示与亮度换成深色,然后上划切换程序,不会变黑,要进入APP了才会变黑,微信上划切换的时候就已经变成了黑色

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.