From e431cf0cff1b6c2345ee29b97ea1830f82fa29b2 Mon Sep 17 00:00:00 2001 From: zhenglibao Date: Tue, 19 Feb 2019 16:12:45 +0800 Subject: [PATCH] =?UTF-8?q?UILabel=E6=94=AF=E6=8C=81=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96=EF=BC=8CFlexXmlBaseView=E6=94=AF=E6=8C=81=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=96=B9=E5=BC=8F=E5=88=9B=E5=BB=BA=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0FrameView=E7=BB=84=E4=BB=B6=E7=9A=84=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++ Example/FlexLib.xcodeproj/project.pbxproj | 10 +++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++ Example/FlexLib/FlexViewController.m | 9 +++ Example/FlexLib/TestFrameView.h | 17 ++++++ Example/FlexLib/TestFrameView.m | 61 +++++++++++++++++++ Example/FlexLib/en.lproj/Localizable.strings | 2 + Example/FlexLib/res/FlexViewController.xml | 11 ++++ Example/FlexLib/res/TestFrameView.xml | 12 ++++ Example/FlexLib/res/TestScrollVC.xml | 2 +- .../FlexLib/zh-Hans.lproj/Localizable.strings | 1 + .../FlexSwiftDemo.xcodeproj/project.pbxproj | 20 ++++++ Example/FlexSwiftDemo/TestFrameView.swift | 59 ++++++++++++++++++ Example/FlexSwiftDemo/ViewController.swift | 7 +++ Example/FlexSwiftDemo/res/TestFrameView.xml | 12 ++++ Example/FlexSwiftDemo/res/ViewController.xml | 11 ++++ FlexLib.podspec | 2 +- FlexLib/Classes/FlexFrameView.h | 2 + FlexLib/Classes/FlexNode.h | 1 + FlexLib/Classes/FlexNode.m | 54 ++++++++++------ FlexLib/Classes/FlexXmlBaseView.h | 9 ++- FlexLib/Classes/FlexXmlBaseView.m | 9 +++ FlexLib/Classes/ViewExt/UILabel+Flex.m | 1 + 23 files changed, 302 insertions(+), 22 deletions(-) create mode 100644 Example/FlexLib.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Example/FlexLib/TestFrameView.h create mode 100644 Example/FlexLib/TestFrameView.m create mode 100644 Example/FlexLib/res/TestFrameView.xml create mode 100644 Example/FlexSwiftDemo/TestFrameView.swift create mode 100644 Example/FlexSwiftDemo/res/TestFrameView.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 50f7d29..78b7372 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ **FlexLib**的所有版本的变更日志都将会在这里记录. --- +## 2.2.1 +1. UILabel的富文本支持国际化 +2. FlexXmlBaseView增加代码创建方式 + ## 2.2.0 1. 增加FlexXmlBaseView,该类用来制作组件,与FlexCustomBaseView类似,不同的是FlexXmlBaseView的派生类只能用在xml中,好处是减少视图层级 diff --git a/Example/FlexLib.xcodeproj/project.pbxproj b/Example/FlexLib.xcodeproj/project.pbxproj index 1ddba53..3606deb 100644 --- a/Example/FlexLib.xcodeproj/project.pbxproj +++ b/Example/FlexLib.xcodeproj/project.pbxproj @@ -111,6 +111,8 @@ D297583D1FE0D069004314CF /* qrcode.png in Resources */ = {isa = PBXBuildFile; fileRef = D297583C1FE0D069004314CF /* qrcode.png */; }; D297585E1FE22CF2004314CF /* DemoFlexVC.m in Sources */ = {isa = PBXBuildFile; fileRef = D297585D1FE22CF2004314CF /* DemoFlexVC.m */; }; D29758601FE23DCD004314CF /* justifyContent.xml in Resources */ = {isa = PBXBuildFile; fileRef = D297585F1FE23DCC004314CF /* justifyContent.xml */; }; + D29D0D57221BE9B400DE5543 /* TestFrameView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29D0D56221BE9B400DE5543 /* TestFrameView.m */; }; + D29D0D59221BEA2500DE5543 /* TestFrameView.xml in Resources */ = {isa = PBXBuildFile; fileRef = D29D0D58221BEA2500DE5543 /* TestFrameView.xml */; }; D2CF9CC11FD7EB0900554A0C /* return@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D2CF9CBA1FD7EB0900554A0C /* return@2x.png */; }; D2CF9CC21FD7EB0900554A0C /* addnewtype@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D2CF9CBB1FD7EB0900554A0C /* addnewtype@2x.png */; }; D2CF9CC31FD7EB0900554A0C /* TestTableCell.xml in Resources */ = {isa = PBXBuildFile; fileRef = D2CF9CBC1FD7EB0900554A0C /* TestTableCell.xml */; }; @@ -293,6 +295,9 @@ D297585C1FE22CF2004314CF /* DemoFlexVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoFlexVC.h; sourceTree = ""; }; D297585D1FE22CF2004314CF /* DemoFlexVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DemoFlexVC.m; sourceTree = ""; }; D297585F1FE23DCC004314CF /* justifyContent.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = justifyContent.xml; path = res/justifyContent.xml; sourceTree = ""; }; + D29D0D55221BE9B400DE5543 /* TestFrameView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestFrameView.h; sourceTree = ""; }; + D29D0D56221BE9B400DE5543 /* TestFrameView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TestFrameView.m; sourceTree = ""; }; + D29D0D58221BEA2500DE5543 /* TestFrameView.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = TestFrameView.xml; path = res/TestFrameView.xml; sourceTree = ""; }; D2CF9CBA1FD7EB0900554A0C /* return@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "return@2x.png"; path = "res/return@2x.png"; sourceTree = ""; }; D2CF9CBB1FD7EB0900554A0C /* addnewtype@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "addnewtype@2x.png"; path = "res/addnewtype@2x.png"; sourceTree = ""; }; D2CF9CBC1FD7EB0900554A0C /* TestTableCell.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = TestTableCell.xml; path = res/TestTableCell.xml; sourceTree = ""; }; @@ -424,6 +429,8 @@ D272A8CE1FDA63000075DB1D /* TestModalVC.m */, D2208DD02205938F00B6819E /* TestXmlView.h */, D2208DD12205938F00B6819E /* TestXmlView.m */, + D29D0D55221BE9B400DE5543 /* TestFrameView.h */, + D29D0D56221BE9B400DE5543 /* TestFrameView.m */, D2CF9CC91FD7EB1900554A0C /* TestVC.h */, D2CF9CCA1FD7EB1900554A0C /* TestVC.m */, D28F172A200854E500F5AEB2 /* ControlsVC.h */, @@ -608,6 +615,7 @@ D2CF9CB91FD7EAFA00554A0C /* res */ = { isa = PBXGroup; children = ( + D29D0D58221BEA2500DE5543 /* TestFrameView.xml */, D2208DCE2205937300B6819E /* TestXmlView.xml */, D2EDA728214B8D7400B6A26D /* TestCollectionCell.xml */, D2EDA723214B8B5C00B6A26D /* TestCollectionViewVC.xml */, @@ -798,6 +806,7 @@ D297583D1FE0D069004314CF /* qrcode.png in Resources */, D272A8D31FDA66220075DB1D /* arrow_right@2x.png in Resources */, D29758601FE23DCD004314CF /* justifyContent.xml in Resources */, + D29D0D59221BEA2500DE5543 /* TestFrameView.xml in Resources */, D2208DCF2205937400B6819E /* TestXmlView.xml in Resources */, D24F2EAD1FF3C2D000762ADC /* TableHeader.xml in Resources */, D2CF9CC11FD7EB0900554A0C /* return@2x.png in Resources */, @@ -919,6 +928,7 @@ D297585E1FE22CF2004314CF /* DemoFlexVC.m in Sources */, 6003F59E195388D20070C39A /* FlexAppDelegate.m in Sources */, D272A8C21FD933710075DB1D /* TestScrollVC.m in Sources */, + D29D0D57221BE9B400DE5543 /* TestFrameView.m in Sources */, D272A8E01FDC0DD90075DB1D /* TestLoginVC.m in Sources */, D24F2EBF1FF687C400762ADC /* AttachmentView.m in Sources */, D2CF9CD01FD7EB1A00554A0C /* TestTableVC.m in Sources */, diff --git a/Example/FlexLib.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/FlexLib.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/FlexLib.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/FlexLib/FlexViewController.m b/Example/FlexLib/FlexViewController.m index 96bc94a..4ad76ab 100644 --- a/Example/FlexLib/FlexViewController.m +++ b/Example/FlexLib/FlexViewController.m @@ -19,6 +19,7 @@ #import "ControlsVC.h" #import "FrameVC.h" #import "TestCollectionViewVC.h" +#import "TestFrameView.h" @interface FlexViewController () { @@ -82,4 +83,12 @@ -(void)onExplorerFlex { [FlexHttpVC presentInVC:self]; } +-(void)onFrameView +{ + CGRect rcFrame = [[UIScreen mainScreen]bounds]; + rcFrame.origin.y = 100; + rcFrame.size.height = 500; + TestFrameView* frameview=[[TestFrameView alloc]initWithFlex:nil Frame:rcFrame Owner:nil]; + [self.view addSubview:frameview]; +} @end diff --git a/Example/FlexLib/TestFrameView.h b/Example/FlexLib/TestFrameView.h new file mode 100644 index 0000000..8b05b15 --- /dev/null +++ b/Example/FlexLib/TestFrameView.h @@ -0,0 +1,17 @@ +// +// TestFrameView.h +// FlexLib_Example +// +// Created by 郑立宝 on 2019/2/19. +// Copyright © 2019年 zhenglibao. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface TestFrameView : FlexFrameView + +@end + +NS_ASSUME_NONNULL_END diff --git a/Example/FlexLib/TestFrameView.m b/Example/FlexLib/TestFrameView.m new file mode 100644 index 0000000..eb1a04a --- /dev/null +++ b/Example/FlexLib/TestFrameView.m @@ -0,0 +1,61 @@ +// +// TestFrameView.m +// FlexLib_Example +// +// Created by 郑立宝 on 2019/2/19. +// Copyright © 2019年 zhenglibao. All rights reserved. +// +// Describe + +#import "TestFrameView.h" + +@interface TestFrameView() +{ + UIView* _attachParent; +} +@end + +@implementation TestFrameView + +-(void)onClose +{ + [self removeFromSuperview]; +} +-(void)removeCell:(UIGestureRecognizer*)sender +{ + UIView* cell = sender.view; + [cell removeFromSuperview]; + [_attachParent markDirty]; +} +-(void)onAddAttachment +{ + UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeCell:)]; + UIView* cell = [[UIView alloc]init]; + + [_attachParent addSubview:cell]; + + [cell enableFlexLayout:YES]; + [cell addGestureRecognizer:tap]; + [cell setLayoutAttrStrings:@[ + @"width",@"80%", + @"height",@"44", + @"marginTop",@"5", + @"marginBottom",@"5", + @"alignItems",@"center", + @"justifyContent",@"center", + ]]; + [cell setViewAttr:@"bgColor" Value:@"#e5e5e5"]; + + UILabel* label=[UILabel new]; + [cell addSubview:label]; + [label enableFlexLayout:YES]; + [label setViewAttrStrings:@[ + @"fontSize",@"16", + @"color",@"red", + @"text",@"点我删除", + ]]; + + [_attachParent markDirty]; +} + +@end diff --git a/Example/FlexLib/en.lproj/Localizable.strings b/Example/FlexLib/en.lproj/Localizable.strings index 5320443..e367eee 100644 --- a/Example/FlexLib/en.lproj/Localizable.strings +++ b/Example/FlexLib/en.lproj/Localizable.strings @@ -8,3 +8,5 @@ */ "multilangdemo" = "This string is multi-language demo. You can change system language to see the effect. This example only support English & Chinese."; +"uilabellang" = "This is Richtext UILabel control(Multi-language support),"; + diff --git a/Example/FlexLib/res/FlexViewController.xml b/Example/FlexLib/res/FlexViewController.xml index 2e5d0e0..388b711 100644 --- a/Example/FlexLib/res/FlexViewController.xml +++ b/Example/FlexLib/res/FlexViewController.xml @@ -67,5 +67,16 @@ + + + + + + + + + + diff --git a/Example/FlexLib/res/TestFrameView.xml b/Example/FlexLib/res/TestFrameView.xml new file mode 100644 index 0000000..415bd30 --- /dev/null +++ b/Example/FlexLib/res/TestFrameView.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Example/FlexLib/res/TestScrollVC.xml b/Example/FlexLib/res/TestScrollVC.xml index a85487a..158b029 100644 --- a/Example/FlexLib/res/TestScrollVC.xml +++ b/Example/FlexLib/res/TestScrollVC.xml @@ -42,7 +42,7 @@ - + diff --git a/Example/FlexLib/zh-Hans.lproj/Localizable.strings b/Example/FlexLib/zh-Hans.lproj/Localizable.strings index d54537e..704cd42 100644 --- a/Example/FlexLib/zh-Hans.lproj/Localizable.strings +++ b/Example/FlexLib/zh-Hans.lproj/Localizable.strings @@ -8,3 +8,4 @@ */ "multilangdemo" = "这条字符串用来展示多语言支持能力,你可以切换系统语言来看看效果,这个demo仅支持中文和英文"; +"uilabellang" = "这是一个富文本的UILabel控件(支持多语言),"; diff --git a/Example/FlexSwiftDemo.xcodeproj/project.pbxproj b/Example/FlexSwiftDemo.xcodeproj/project.pbxproj index 73b1d49..a92d4e3 100644 --- a/Example/FlexSwiftDemo.xcodeproj/project.pbxproj +++ b/Example/FlexSwiftDemo.xcodeproj/project.pbxproj @@ -14,6 +14,11 @@ D272B78B1FEF6770004447E2 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D272B78D1FEF6770004447E2 /* Localizable.strings */; }; D28F173020087B3100F5AEB2 /* Controls.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28F172F20087B3100F5AEB2 /* Controls.swift */; }; D28F173220087EEB00F5AEB2 /* Controls.xml in Resources */ = {isa = PBXBuildFile; fileRef = D28F173120087EEB00F5AEB2 /* Controls.xml */; }; + D29D0D5B221BEF0700DE5543 /* TestFrameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D29D0D5A221BEF0700DE5543 /* TestFrameView.swift */; }; + D29D0D60221BF14400DE5543 /* TestFrameView.xml in Resources */ = {isa = PBXBuildFile; fileRef = D29D0D5C221BF14300DE5543 /* TestFrameView.xml */; }; + D29D0D61221BF14400DE5543 /* TableHeader.xml in Resources */ = {isa = PBXBuildFile; fileRef = D29D0D5D221BF14400DE5543 /* TableHeader.xml */; }; + D29D0D62221BF14400DE5543 /* TestXmlView.xml in Resources */ = {isa = PBXBuildFile; fileRef = D29D0D5E221BF14400DE5543 /* TestXmlView.xml */; }; + D29D0D63221BF14400DE5543 /* AttachmentView.xml in Resources */ = {isa = PBXBuildFile; fileRef = D29D0D5F221BF14400DE5543 /* AttachmentView.xml */; }; D2D0206A1FEBA946008F6DB6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D020691FEBA946008F6DB6 /* AppDelegate.swift */; }; D2D0206C1FEBA946008F6DB6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2D0206B1FEBA946008F6DB6 /* ViewController.swift */; }; D2D020711FEBA946008F6DB6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D2D020701FEBA946008F6DB6 /* Assets.xcassets */; }; @@ -63,6 +68,11 @@ D272B78E1FEF6774004447E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; D28F172F20087B3100F5AEB2 /* Controls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Controls.swift; sourceTree = ""; }; D28F173120087EEB00F5AEB2 /* Controls.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = Controls.xml; path = FlexSwiftDemo/res/Controls.xml; sourceTree = SOURCE_ROOT; }; + D29D0D5A221BEF0700DE5543 /* TestFrameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestFrameView.swift; sourceTree = ""; }; + D29D0D5C221BF14300DE5543 /* TestFrameView.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = TestFrameView.xml; path = FlexSwiftDemo/res/TestFrameView.xml; sourceTree = SOURCE_ROOT; }; + D29D0D5D221BF14400DE5543 /* TableHeader.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = TableHeader.xml; path = FlexSwiftDemo/res/TableHeader.xml; sourceTree = SOURCE_ROOT; }; + D29D0D5E221BF14400DE5543 /* TestXmlView.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = TestXmlView.xml; path = FlexSwiftDemo/res/TestXmlView.xml; sourceTree = SOURCE_ROOT; }; + D29D0D5F221BF14400DE5543 /* AttachmentView.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = AttachmentView.xml; path = FlexSwiftDemo/res/AttachmentView.xml; sourceTree = SOURCE_ROOT; }; D2D020661FEBA946008F6DB6 /* FlexSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlexSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; D2D020691FEBA946008F6DB6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; D2D0206B1FEBA946008F6DB6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -169,6 +179,7 @@ D2D020B31FEC9B53008F6DB6 /* TestJustifycontentVC.swift */, D2D020B51FECB39C008F6DB6 /* TestTableCell.swift */, D2E0E2AA22059AC800D24288 /* TestXmlView.swift */, + D29D0D5A221BEF0700DE5543 /* TestFrameView.swift */, D28F172F20087B3100F5AEB2 /* Controls.swift */, D272B78D1FEF6770004447E2 /* Localizable.strings */, ); @@ -179,6 +190,10 @@ isa = PBXGroup; children = ( D2E0E2A822059A9E00D24288 /* TestXmlView.xml */, + D29D0D5F221BF14400DE5543 /* AttachmentView.xml */, + D29D0D5D221BF14400DE5543 /* TableHeader.xml */, + D29D0D5C221BF14300DE5543 /* TestFrameView.xml */, + D29D0D5E221BF14400DE5543 /* TestXmlView.xml */, D2E8049720280D9200B54656 /* FrameVC.xml */, D28F173120087EEB00F5AEB2 /* Controls.xml */, D24F2EC21FF72CEB00762ADC /* AttachmentView.xml */, @@ -271,12 +286,15 @@ files = ( D2E0E2A922059A9E00D24288 /* TestXmlView.xml in Resources */, D24F2EAF1FF3CEB000762ADC /* TableHeader.xml in Resources */, + D29D0D60221BF14400DE5543 /* TestFrameView.xml in Resources */, D2D020971FEBB289008F6DB6 /* return@2x.png in Resources */, + D29D0D63221BF14400DE5543 /* AttachmentView.xml in Resources */, D2D020951FEBB289008F6DB6 /* example1.jpg in Resources */, D2D0209B1FEBB289008F6DB6 /* batchcheck@2x.png in Resources */, D2D0209E1FEBB289008F6DB6 /* TextViewVC.xml in Resources */, D2D020991FEBB289008F6DB6 /* alignItems.xml in Resources */, D2D020A41FEBB289008F6DB6 /* system.style in Resources */, + D29D0D61221BF14400DE5543 /* TableHeader.xml in Resources */, D2D020A01FEBB289008F6DB6 /* justifyContent.xml in Resources */, D2D020981FEBB289008F6DB6 /* TestScrollVC.xml in Resources */, D2D020961FEBB289008F6DB6 /* TestModalVC.xml in Resources */, @@ -291,6 +309,7 @@ D28F173220087EEB00F5AEB2 /* Controls.xml in Resources */, D2D0209A1FEBB289008F6DB6 /* ViewController.xml in Resources */, D2D020A61FEBB289008F6DB6 /* test.xml in Resources */, + D29D0D62221BF14400DE5543 /* TestXmlView.xml in Resources */, D2D020711FEBA946008F6DB6 /* Assets.xcassets in Resources */, D2D0209C1FEBB289008F6DB6 /* TestTableCell.xml in Resources */, D2D020A31FEBB289008F6DB6 /* splash.png in Resources */, @@ -349,6 +368,7 @@ files = ( D2E0E2AB22059AC800D24288 /* TestXmlView.swift in Sources */, D2D020B21FEC9B31008F6DB6 /* TestTextviewVC.swift in Sources */, + D29D0D5B221BEF0700DE5543 /* TestFrameView.swift in Sources */, D28F173020087B3100F5AEB2 /* Controls.swift in Sources */, D2D020AE1FEC9A00008F6DB6 /* TestModalVC.swift in Sources */, D2D020B61FECB39C008F6DB6 /* TestTableCell.swift in Sources */, diff --git a/Example/FlexSwiftDemo/TestFrameView.swift b/Example/FlexSwiftDemo/TestFrameView.swift new file mode 100644 index 0000000..1b8bd62 --- /dev/null +++ b/Example/FlexSwiftDemo/TestFrameView.swift @@ -0,0 +1,59 @@ +// +// TestFrameView.swift +// FlexSwiftDemo +// +// Created by 郑立宝 on 2019/2/19. +// Copyright © 2019年 wbg. All rights reserved. +// + +import Foundation +import FlexLib + +@objc(TestFrameView) +class TestFrameView: FlexFrameView { + + @objc var _attachParent : UIView! + + @objc(onClose) + func onClose()->Void{ + self.removeFromSuperview() + } + + @objc(removeCell:) + func removeCell(sender : UIGestureRecognizer) -> Void { + let cell = sender.view! + cell.removeFromSuperview() + _attachParent.markDirty() + } + + @objc + func onAddAttachment() -> Void { + let tap = UITapGestureRecognizer.init(target: self, action: #selector(AttachmentView.removeCell(sender:))) + let cell = UIView() + cell.enableFlexLayout(true) + cell.addGestureRecognizer(tap) + cell.setLayoutAttrStrings([ + "width","80%", + "height","44", + "marginTop","5", + "marginBottom","5", + "alignItems","center", + "justifyContent","center", + ]) + + cell.setViewAttr("bgColor", value: "#e5e5e5") + _attachParent.addSubview(cell) + + let label = UILabel() + label.enableFlexLayout(true) + label.setViewAttrStrings([ + "fontSize","16", + "color","red", + "text","点我删除", + ]) + cell.addSubview(label) + + _attachParent.markDirty() + } + +} diff --git a/Example/FlexSwiftDemo/ViewController.swift b/Example/FlexSwiftDemo/ViewController.swift index ac2717e..26f7be3 100644 --- a/Example/FlexSwiftDemo/ViewController.swift +++ b/Example/FlexSwiftDemo/ViewController.swift @@ -71,6 +71,13 @@ class ViewController: FlexBaseVC { @objc func onExplorerFlex()->Void{ FlexHttpVC.present(inVC: self) } + @objc func onFrameView()->Void{ + var frame = UIScreen.main.bounds; + frame.origin.y = 100 + frame.size.height=400 + let view = TestFrameView.init(flex: nil, frame: frame, owner: nil) + self.view.addSubview(view!) + } } diff --git a/Example/FlexSwiftDemo/res/TestFrameView.xml b/Example/FlexSwiftDemo/res/TestFrameView.xml new file mode 100644 index 0000000..415bd30 --- /dev/null +++ b/Example/FlexSwiftDemo/res/TestFrameView.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Example/FlexSwiftDemo/res/ViewController.xml b/Example/FlexSwiftDemo/res/ViewController.xml index 4092d22..4fb5918 100644 --- a/Example/FlexSwiftDemo/res/ViewController.xml +++ b/Example/FlexSwiftDemo/res/ViewController.xml @@ -66,5 +66,16 @@ attr="@:system/buttonText,text:Online Flex Explorer"/> + + + + + + + + + + diff --git a/FlexLib.podspec b/FlexLib.podspec index 23d26e4..cd56a5e 100644 --- a/FlexLib.podspec +++ b/FlexLib.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'FlexLib' - s.version = '2.2.0' + s.version = '2.2.1' s.summary = 'An obj-c flex layout framework for IOS' # This description is used to generate tags and improve search results. diff --git a/FlexLib/Classes/FlexFrameView.h b/FlexLib/Classes/FlexFrameView.h index f1bc020..db278f6 100644 --- a/FlexLib/Classes/FlexFrameView.h +++ b/FlexLib/Classes/FlexFrameView.h @@ -16,6 +16,7 @@ typedef void (^FrameChanged)(CGRect); // This view not use flexlbox layout // just set frame or make flexible width // or height +// 该类也支持继承并创建组件 @interface FlexFrameView : UIView @@ -29,6 +30,7 @@ typedef void (^FrameChanged)(CGRect); //如果外部直接设置其frame,将不会调用 @property(nonatomic,copy) FrameChanged _Nullable onFrameChange; +//如果用来制作组件的时候,调用initWithFlex初始化的时候一定要给owner传递nil -(instancetype _Nullable )initWithFlex:(nullable NSString*)flexname Frame:(CGRect)frame Owner:(nullable NSObject*)owner; diff --git a/FlexLib/Classes/FlexNode.h b/FlexLib/Classes/FlexNode.h index 728a519..0e6ec84 100644 --- a/FlexLib/Classes/FlexNode.h +++ b/FlexLib/Classes/FlexNode.h @@ -148,5 +148,6 @@ void FlexSetCustomScale(FlexScaleFunc scaleFunc); NSMutableAttributedString* createAttributedString(NSArray* childElems, NSObject* owner, UIFont* defaultFont, + UIColor* defaultColor, NSMutableArray* clicks); diff --git a/FlexLib/Classes/FlexNode.m b/FlexLib/Classes/FlexNode.m index fded40f..a68cf5d 100644 --- a/FlexLib/Classes/FlexNode.m +++ b/FlexLib/Classes/FlexNode.m @@ -155,6 +155,30 @@ static YGValue String2YGValue(const char* s, } return s; } + +NSString* FlexProcessAttrValue(NSString* attrName, + NSString* attrValue, + NSObject* owner) +{ + // '*abc' means scale the value by the screen size, + // '**abc' means '*abc' + if(attrValue.length>=2 && [attrValue characterAtIndex:0]=='*') + { + NSString* v = [attrValue substringFromIndex:1]; + if([v hasPrefix:@"*"]){ + attrValue = v; + }else{ + float f=[v floatValue]; + f = gScaleFunc(f,[attrName cStringUsingEncoding:NSASCIIStringEncoding]); + attrValue=[NSString stringWithFormat:@"%f",f]; + } + } + + // localize value + attrValue = FlexLocalizeValue(attrValue, owner); + return attrValue; +} + void FlexSetViewAttr(UIView* view, NSString* attrName, NSString* attrValue, @@ -178,22 +202,7 @@ void FlexSetViewAttr(UIView* view, return ; } - // '*abc' means scale the value by the screen size, - // '**abc' means '*abc' - if(attrValue.length>=2 && [attrValue characterAtIndex:0]=='*') - { - NSString* v = [attrValue substringFromIndex:1]; - if([v hasPrefix:@"*"]){ - attrValue = v; - }else{ - float f=[v floatValue]; - f = gScaleFunc(f,[attrName cStringUsingEncoding:NSASCIIStringEncoding]); - attrValue=[NSString stringWithFormat:@"%f",f]; - } - } - - // localize value - attrValue = FlexLocalizeValue(attrValue, owner); + attrValue = FlexProcessAttrValue(attrName,attrValue, owner); @try{ @@ -1008,13 +1017,16 @@ - (id)copyWithZone:(NSZone *)zone { static NSAttributedString* createAttributedText(FlexNode* node, NSObject* owner, - UIFont* defaultFont) + UIFont* defaultFont, + UIColor* defaultColor) { NSString* text = @""; NSMutableDictionary* dict = [NSMutableDictionary dictionary]; for (FlexAttr* attr in node.viewAttrs) { + attr.value = FlexProcessAttrValue(attr.name, attr.value, owner); + if( [attr.name isEqualToString:@"text"] ){ text = attr.value; @@ -1060,6 +1072,9 @@ - (id)copyWithZone:(NSZone *)zone { if( [dict objectForKey:NSFontAttributeName]==nil && defaultFont!=nil ){ [dict setObject:defaultFont forKey:NSFontAttributeName]; } + if( [dict objectForKey:NSForegroundColorAttributeName]==nil && defaultColor!=nil ){ + [dict setObject:defaultColor forKey:NSForegroundColorAttributeName]; + } return [[NSAttributedString alloc]initWithString:text attributes:dict]; } @@ -1069,6 +1084,8 @@ - (id)copyWithZone:(NSZone *)zone { for (FlexAttr* attr in node.viewAttrs) { + attr.value = FlexProcessAttrValue(attr.name, attr.value, owner); + if( [attr.name isEqualToString:@"source"] ){ UIImage* img = [UIImage imageNamed:attr.value inBundle:[owner bundleForImages] compatibleWithTraitCollection:nil]; attach.image = img ; @@ -1097,6 +1114,7 @@ - (id)copyWithZone:(NSZone *)zone { NSMutableAttributedString* createAttributedString(NSArray* childElems, NSObject* owner, UIFont* defaultFont, + UIColor* defaultColor, NSMutableArray* clicks) { NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc]init]; @@ -1107,7 +1125,7 @@ - (id)copyWithZone:(NSZone *)zone { if( [node.viewClassName isEqualToString:@"Text"] ){ - [attrString appendAttributedString:createAttributedText(node,owner,defaultFont)]; + [attrString appendAttributedString:createAttributedText(node,owner,defaultFont,defaultColor)]; }else if( [node.viewClassName isEqualToString:@"Image"] ){ diff --git a/FlexLib/Classes/FlexXmlBaseView.h b/FlexLib/Classes/FlexXmlBaseView.h index 1d9727e..956de15 100644 --- a/FlexLib/Classes/FlexXmlBaseView.h +++ b/FlexLib/Classes/FlexXmlBaseView.h @@ -7,18 +7,23 @@ #import +@class FlexRootView; + NS_ASSUME_NONNULL_BEGIN /* * 用来制作基于xml的组件的基类,该类与FlexCustomBaseView的区别是: * FlexCustomBaseView的派生类既可以用在xml中,也可以像传统的UIView派生类 * 那样使用initWithFrame创建,缺点是会额外的增加多余的视图层级 - * FlexXmlBaseView仅能使用在xml文件中,不能使用代码方式(通过init或者initWithFrame)创建,也 - * 不能直接设置frame,优点是更加轻量级,不会增加额外的视图层级 + * FlexXmlBaseView能使用在xml文件中,可以通过initWithRootView方式创建,但不能通过 + * initWithFrame创建,也不能能直接设置frame,优点是更加轻量级,不会增加额外的视图层级 */ @interface FlexXmlBaseView : UIView +/// 用代码的方式创建视图组件 +-(instancetype)initWithRootView:(FlexRootView*)rootview; + /// 子类可以重写这个方法来做额外的初始化工作 -(void)onInit; diff --git a/FlexLib/Classes/FlexXmlBaseView.m b/FlexLib/Classes/FlexXmlBaseView.m index d48561b..b71b04d 100644 --- a/FlexLib/Classes/FlexXmlBaseView.m +++ b/FlexLib/Classes/FlexXmlBaseView.m @@ -47,6 +47,15 @@ - (instancetype)initWithCoder:(NSCoder *)coder return self; } +-(instancetype)initWithRootView:(FlexRootView*)rootview +{ + self = [self init]; + if (self) { + [self afterInit:self rootView:rootview]; + } + return self; +} + - (void)afterInit:(NSObject *)owner rootView:(FlexRootView *)rootView { FlexNode* node = self.flexNode ; diff --git a/FlexLib/Classes/ViewExt/UILabel+Flex.m b/FlexLib/Classes/ViewExt/UILabel+Flex.m index 68dcdfc..f28b894 100644 --- a/FlexLib/Classes/ViewExt/UILabel+Flex.m +++ b/FlexLib/Classes/ViewExt/UILabel+Flex.m @@ -238,6 +238,7 @@ -(void)buildChildAttrStrings:(NSObject*)owner NSMutableAttributedString* string = createAttributedString(childElems, owner, self.font, + self.textColor, aryClickRange); if( string.length>0 ){ NSMutableParagraphStyle * style = [self paraStyle];