From 12733213877f127f9d09e9522b67087169d42c9e Mon Sep 17 00:00:00 2001 From: Ajai Prabhu G S Date: Thu, 31 Jan 2019 12:45:46 +0530 Subject: [PATCH] mf textview similar to BR --- MVMCoreUI/Atoms/Views/MFTextView.h | 8 +++++ MVMCoreUI/Atoms/Views/MFTextView.m | 50 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/MFTextView.h b/MVMCoreUI/Atoms/Views/MFTextView.h index b1c80bdd..9d568b6a 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.h +++ b/MVMCoreUI/Atoms/Views/MFTextView.h @@ -7,6 +7,7 @@ // #import +#import "SeparatorView.h" @interface CustomTextView: UITextView @@ -25,7 +26,14 @@ @property (weak, nonatomic) id delegate; @property (weak, nonatomic) IBOutlet CustomTextView *textView; +@property (assign, nonatomic) BOOL hideBorder; +@property (strong, nonatomic) UIBezierPath *borderPath; +@property (nonatomic, readwrite) BOOL errorShowing; +@property (weak, nonatomic) SeparatorView *bottomLine; + +(MFTextView *) MFTextViewWithPlaceholderString:(NSString *) placeholder delegate:(id) delegate; +- (void)makeBordersForTextView; + @end diff --git a/MVMCoreUI/Atoms/Views/MFTextView.m b/MVMCoreUI/Atoms/Views/MFTextView.m index 1e734e3f..621947cf 100644 --- a/MVMCoreUI/Atoms/Views/MFTextView.m +++ b/MVMCoreUI/Atoms/Views/MFTextView.m @@ -10,6 +10,8 @@ #import "UIColor+MFConvenience.h" #import "MVMCoreUIUtility.h" #import "MVMCoreUIConstants.h" +#import "MFStyler.h" + @import MVMCore.MVMCoreConstants; @protocol CustomTextViewDelegate @@ -163,7 +165,55 @@ view.textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo; } [view didSetFont:view.textView.font]; + +// self.bottomLine = bottomLine; + return view; } + +#pragma mark - bordered textview +- (void)makeBordersForTextView { + + SeparatorView *bottomLine = [SeparatorView separatorAddToView:self position:SeparatorPositionBot]; + self.placeHolderLabel.font = [MFStyler fontB3]; + [self.textView setFont:[MFStyler fontB2]]; + [self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)]; + self.errorShowing = false; +} + +- (void)addBezierPathForBorders { + CGRect frame = self.frame; + self.borderPath = [UIBezierPath bezierPath]; + [self.borderPath moveToPoint:CGPointMake(frame.origin.x, frame.origin.y + frame.size.height)]; + [self.borderPath addLineToPoint:CGPointMake(frame.origin.x, frame.origin.y)]; + [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y)]; + [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)]; + + self.borderPath.lineWidth = 1; + + UIColor *strokeColor; + if (self.errorShowing) { + strokeColor = [UIColor mfPumpkinColor]; + self.bottomLine.backgroundColor = [UIColor mfPumpkinColor]; + } else { + strokeColor = [UIColor mfSilver]; + self.bottomLine.backgroundColor = [UIColor mfSilver]; + } + + [strokeColor setStroke]; + + [self.borderPath stroke]; +} + +- (void)drawRect:(CGRect)rect { + [super drawRect:rect]; + [self.borderPath removeAllPoints]; + self.layer.cornerRadius = 0; + self.hideBorder = false; + if (!self.hideBorder) { + [self addBezierPathForBorders]; + } +} + @end