Browse Source

no message

zzb 3 years ago
parent
commit
a524e1d712

+ 16 - 0
ZZUIKit/Classes/Ex/View/UIView+Shape.h

@@ -0,0 +1,16 @@
+//
+//  UIView+Shape.h
+//  IHWristband
+//
+//  Created by Max on 2021/12/19.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface UIView (Shape)
++ (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor;
+@end
+
+NS_ASSUME_NONNULL_END

+ 41 - 0
ZZUIKit/Classes/Ex/View/UIView+Shape.m

@@ -0,0 +1,41 @@
+//
+//  UIView+Shape.m
+//  IHWristband
+//
+//  Created by Max on 2021/12/19.
+//
+
+#import "UIView+Shape.h"
+
+@implementation UIView (Shape)
+
+/**
+  ** lineView:       需要绘制成虚线的view
+  ** lineLength:     虚线的宽度
+  ** lineSpacing:    虚线的间距
+  ** lineColor:      虚线的颜色
+  **/
++ (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
+{
+      CAShapeLayer *shapeLayer = [CAShapeLayer layer];
+      [shapeLayer setBounds:lineView.bounds];
+      [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
+      [shapeLayer setFillColor:[UIColor clearColor].CGColor];
+      //  设置虚线颜色为blackColor
+      [shapeLayer setStrokeColor:lineColor.CGColor];
+      //  设置虚线宽度
+      [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
+      [shapeLayer setLineJoin:kCALineJoinRound];
+      //  设置线宽,线间距
+      [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
+      //  设置路径
+      CGMutablePathRef path = CGPathCreateMutable();
+      CGPathMoveToPoint(path, NULL, 0, 0);
+      CGPathAddLineToPoint(path, NULL,CGRectGetWidth(lineView.frame), 0);
+      [shapeLayer setPath:path];
+      CGPathRelease(path);
+      //  把绘制好的虚线添加上来
+      [lineView.layer addSublayer:shapeLayer];
+  }
+
+@end

+ 1 - 0
ZZUIKit/Classes/Ex/ZZUIKitEx.h

@@ -31,4 +31,5 @@
 #import <ZZFoundation/ZZFoundation.h>
 
 #import "UITableView+ZZEx.h"
+#import "UIView+Shape.h"
 #endif /* ZZUIKitEx_h */

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

@@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
 /// 计数文字的格式化字符串
 @property(nonatomic,copy,nullable) NSString *countFormat;
 @property(nonatomic,copy) NSString *text;
+@property(nonatomic,strong) FlexTextView *textView;
 
 @end
 

+ 12 - 7
ZZUIKit/Classes/ZZTextWidget/ZZTextInputWidget.m

@@ -10,16 +10,16 @@
 
 @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.countLab.text = [NSString stringWithFormat:self.countFormat,self.currentCount,_maxCount];
     self.textView.placeholder = self.placehold;
     self.textView.font = [UIFont systemFontOfSize:15];
     self.countLab.font = [UIFont systemFontOfSize:15];
@@ -41,13 +41,17 @@
         (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];
+
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,self.currentCount,_maxCount];
+}
+
+-(NSInteger)currentCount{
+    return _textView.text.length > _maxCount ? _maxCount : _textView.text.length;
 }
 
 -(void)setMaxCount:(NSInteger)maxCount{
     _maxCount = maxCount;
-    self.countLab.text = [NSString stringWithFormat:self.countFormat,_currentCount,_maxCount];
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,self.currentCount,_maxCount];
 }
 
 -(void)setPlacehold:(NSString *)placehold{
@@ -75,7 +79,7 @@ FLEXSET(countFont){
 
 FLEXSET(countFormat){
     self.countFormat = sValue;
-    self.countLab.text = [NSString stringWithFormat:self.countFormat,_currentCount,_maxCount];
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,self.currentCount,_maxCount];
 }
 
 -(NSString *)countFormat{
@@ -94,6 +98,7 @@ FLEXSET(countFormat){
 
 -(void)setText:(NSString *)text{
     _textView.text = text;
+    self.countLab.text = [NSString stringWithFormat:self.countFormat,self.currentCount,_maxCount];
 }
 
 -(NSString *)text{