Skip to content

Commit

Permalink
增加动态颜色支持
Browse files Browse the repository at this point in the history
郑立宝 committed Nov 1, 2024
1 parent 67f332f commit 3e87772
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
**FlexLib**的所有版本的变更日志都将会在这里记录.

---
## 3.5.0
1.所有xml中的颜色支持设置动态颜色

## 3.4.0
1.最低支持版本升级为iOS11.0
2.解决了引归档api过期引起的编译警告问题
2 changes: 1 addition & 1 deletion Example_oc/FlexLib/res/FlexViewController.xml
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@



</FlexScrollView><UIView name="bottomBtn" layout="$width:ScreenWidth*0.6,height:50,alignItems:center,justifyContent:center" attr="bgColor:#e5e5e5,borderRadius:6">
</FlexScrollView><UIView name="bottomBtn" layout="$width:ScreenWidth*0.6,height:50,alignItems:center,justifyContent:center" attr="bgColor:#e5e5e5|white,borderRadius:6">
<UILabel
attr="@:system/buttonText,text:表达式计算,屏幕宽度的60%"/>
</UIView>
2 changes: 1 addition & 1 deletion FlexLib.podspec
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'FlexLib'
s.version = '3.4.1'
s.version = '3.5.0'
s.summary = 'An obj-c flex layout framework for IOS & mac'

# This description is used to generate tags and improve search results.
23 changes: 23 additions & 0 deletions FlexLib/Classes/Flexlib/FlexUtils.m
Original file line number Diff line number Diff line change
@@ -112,6 +112,29 @@
UIColor* colorFromString(NSString* clr,
NSObject* owner)
{
if (@available( iOS 13.0, *)) {

NSUInteger loc = [clr rangeOfString:@"|"].location;
if(loc!=NSNotFound)
{
UIColor* lightColor = colorFromString([clr substringToIndex:loc], owner);
UIColor* darkColor = colorFromString([clr substringFromIndex:loc+1], owner);

if(lightColor!=nil && darkColor!=nil)
{
return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
return darkColor;
} else {
return lightColor;
}
}];
}else{
return lightColor?:darkColor;
}
}
}

if(![clr hasPrefix:@"#"]){

if([clr rangeOfString:@"."].length>0){

0 comments on commit 3e87772

Please sign in to comment.