Explorar o código

添加新组建ZZTextInputWidget,修改了ZZOption、ZZRadio,ZZSelect,ZZUIKit

zzb %!s(int64=4) %!d(string=hai) anos
pai
achega
6b3a920fb7

+ 7 - 0
ZZUIKit/Assets/XML/ZZTextInputWidget.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 备注内容 -->
+<UIView layout="flex:1" attr="bgColor:white">
+    <FlexTextView name="textView" attr="placeholder:请输入备注,font:PingFangSC-Regular|15" layout="flex:1"/>
+    <UILabel name="countLab" attr="font:PingFangSC-Regular|15,color:#CCCCCC,text:0/100字" layout="alignSelf:flex-end"/>
+</UIView>

+ 4 - 0
ZZUIKit/Classes/ZZOption/ZZOption.m

@@ -120,4 +120,8 @@ FLEXSET(title){
     self.title = sValue;
     self.titleLab.text = sValue;
 }
+
+-(NSBundle *)bundleForRes{
+    return nil;
+}
 @end

+ 8 - 2
ZZUIKit/Classes/ZZRaido/ZZRadio.m

@@ -70,8 +70,10 @@ FLEXSET(label){
         }
     }
     
-    for (ZZCheckBox *box in _itemArr) {
-        box.selected = false;
+    for (UIView *box in _itemArr) {
+        if ([box respondsToSelector:@selector(setSelected:)]) {
+            [box setValue:@(false) forKey:@"selected"];
+        }
         self.selectStr = nil;
     }
 }
@@ -80,4 +82,8 @@ FLEXSET(label){
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 }
 
+-(NSBundle *)bundleForRes{
+    return nil;
+}
+
 @end

+ 2 - 2
ZZUIKit/Classes/ZZSelect/ZZSelect.h

@@ -12,8 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
 /// 包裹ZZCheckBox
 @interface ZZSelect : FlexCustomBaseView
 /// 选中的标签数组
-@property(nonatomic,strong) NSMutableArray *selectArr;
-@property(nonatomic,copy) void (^selectBlock)(NSMutableArray *arr);
+@property(nonatomic,strong) NSMutableArray<NSString *> *selectArr;
+@property(nonatomic,copy) void (^selectBlock)(NSMutableArray<NSString *> *arr);
 @end
 
 NS_ASSUME_NONNULL_END

+ 24 - 0
ZZUIKit/Classes/ZZTextWidget/ZZTextInputWidget.h

@@ -0,0 +1,24 @@
+//
+//  ZZTextInputWidget.h
+//  ZZUIKit
+//
+//  Created by Max on 2021/4/6.
+//
+
+#import <FlexLib/FlexLib.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ZZTextInputWidget : FlexCustomBaseView
+
+/// 占位文字
+@property(nonatomic,copy) NSString *placehold;
+@property(nonatomic,assign) NSInteger maxCount;
+@property(nonatomic,assign,readonly) NSInteger currentCount;
+/// 计数文字的格式化字符串
+@property(nonatomic,copy,nullable) NSString *countFormat;
+@property(nonatomic,copy) NSString *text;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 102 - 0
ZZUIKit/Classes/ZZTextWidget/ZZTextInputWidget.m

@@ -0,0 +1,102 @@
+//
+//  ZZTextInputWidget.m
+//  ZZUIKit
+//
+//  Created by Max on 2021/4/6.
+//
+
+#import "ZZTextInputWidget.h"
+#import <ZZUIKit/ZZColor.h>
+
+@interface ZZTextInputWidget()
+@property(nonatomic,strong) UILabel *countLab;
+@property(nonatomic,strong) FlexTextView *textView;
+@end
+
+@implementation ZZTextInputWidget
+
+-(void)onInit{
+    _currentCount = 0;
+    self.maxCount = 100;
+    self.placehold = @"请输入";
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,_currentCount,_maxCount];
+    self.textView.placeholder = self.placehold;
+    self.textView.font = [UIFont systemFontOfSize:15];
+    self.countLab.font = [UIFont systemFontOfSize:15];
+    self.textView.textColor = zz_RGBHex(0x333333);
+    self.countLab.textColor = zz_RGBHex(0xCCCCCC);
+    
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(placeholderTextViewdidChange:) name:UITextViewTextDidChangeNotification object:self.textView];
+}
+
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
+- (void)placeholderTextViewdidChange:(NSNotification *)notificat{
+    FlexTextView *textView = (FlexTextView *)notificat.object;
+    if ((textView.text.length > _maxCount) &&
+        (_maxCount != 0) &&
+        (textView.markedTextRange == nil)) {
+        textView.text = [textView.text substringToIndex:_maxCount];
+    }
+    _currentCount = textView.text.length > _maxCount ? _maxCount : textView.text.length;
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,_currentCount,_maxCount];
+}
+
+-(void)setMaxCount:(NSInteger)maxCount{
+    _maxCount = maxCount;
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,_currentCount,_maxCount];
+}
+
+-(void)setPlacehold:(NSString *)placehold{
+    _placehold = placehold;
+    self.textView.placeholder = placehold;
+}
+
+FLEXSET(placehold){
+    self.placehold = sValue;
+}
+
+FLEXSET(maxCount){
+    self.maxCount = [sValue intValue];
+}
+
+FLEXSET(font){
+    UIFont* font = fontFromString(sValue);
+    self.textView.font = font;
+}
+
+FLEXSET(countFont){
+    UIFont* font = fontFromString(sValue);
+    self.countLab.font = font;
+}
+
+FLEXSET(countFormat){
+    self.countFormat = sValue;
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,_currentCount,_maxCount];
+}
+
+-(NSString *)countFormat{
+    if (_countFormat) {
+        return _countFormat;
+    }
+    return @"%zd/%zd";
+}
+
+-(NSBundle *)bundleForRes{
+    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+    NSURL *bundleURL = [bundle URLForResource:@"ZZUIKit" withExtension:@"bundle"];
+    NSBundle *resourceBundle = [NSBundle bundleWithURL: bundleURL];
+    return resourceBundle;
+}
+
+-(void)setText:(NSString *)text{
+    _textView.text = text;
+}
+
+-(NSString *)text{
+    return _textView.text;
+}
+@end

+ 1 - 0
ZZUIKit/Classes/ZZTextWidget/ZZTextWidget.h

@@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
 @property (strong, nonatomic) UILabel *wordNumLabel;
 @property (copy, nonatomic) NSString *wordNumFormat;
 
+
 //文字输入
 @property (copy, nonatomic) void(^didChangeText)(ZZTextWidget *textView);
 - (void)didChangeText:(void(^)(ZZTextWidget *textView))block;

+ 1 - 0
ZZUIKit/Classes/ZZUIKit.h

@@ -28,6 +28,7 @@
 #import "ZZTextImgView.h"
 
 #import "ZZTextWidget.h"
+#import "ZZTextInputWidget.h"
 
 
 #endif /* ZZUIKit_h */