Merge branch 'develop' of https://onestash.verizon.com/scm/bphvb/mvm_core_ui into develop
This commit is contained in:
commit
83aa4d91e6
@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "SeparatorView.h"
|
||||||
|
|
||||||
@interface CustomTextView: UITextView
|
@interface CustomTextView: UITextView
|
||||||
|
|
||||||
@ -23,9 +24,16 @@
|
|||||||
|
|
||||||
@interface MFTextView : UIView <UITextViewDelegate>
|
@interface MFTextView : UIView <UITextViewDelegate>
|
||||||
|
|
||||||
@property (weak, nonatomic) id delegate;
|
@property (weak, nonatomic, nullable) id delegate;
|
||||||
@property (weak, nonatomic) IBOutlet CustomTextView *textView;
|
@property (weak, nonatomic) IBOutlet CustomTextView *textView;
|
||||||
|
@property (assign, nonatomic) BOOL hideBorder;
|
||||||
|
@property (strong, nonatomic, nullable) UIBezierPath *borderPath;
|
||||||
|
@property (nonatomic, readwrite) BOOL errorShowing;
|
||||||
|
@property (weak, nonatomic, nullable) SeparatorView *bottomLine;
|
||||||
|
|
||||||
+(MFTextView *) MFTextViewWithPlaceholderString:(NSString *) placeholder delegate:(id) delegate;
|
+(MFTextView *_Nullable) MFTextViewWithPlaceholderString:(NSString *_Nullable) placeholder delegate:(id _Nullable ) delegate;
|
||||||
|
|
||||||
|
//This method will make the UI as per brand refresh (Similar to UITextField)
|
||||||
|
- (void)makeBordersForTextView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -10,6 +10,9 @@
|
|||||||
#import "UIColor+MFConvenience.h"
|
#import "UIColor+MFConvenience.h"
|
||||||
#import "MVMCoreUIUtility.h"
|
#import "MVMCoreUIUtility.h"
|
||||||
#import "MVMCoreUIConstants.h"
|
#import "MVMCoreUIConstants.h"
|
||||||
|
#import "MFStyler.h"
|
||||||
|
#import "MVMCoreUICommonViewsUtility.h"
|
||||||
|
|
||||||
@import MVMCore.MVMCoreConstants;
|
@import MVMCore.MVMCoreConstants;
|
||||||
|
|
||||||
@protocol CustomTextViewDelegate <UITextViewDelegate>
|
@protocol CustomTextViewDelegate <UITextViewDelegate>
|
||||||
@ -18,6 +21,7 @@
|
|||||||
-(void) didSetFont:(UIFont *) font;
|
-(void) didSetFont:(UIFont *) font;
|
||||||
-(void) didSetContainerInset:(UIEdgeInsets)textContainerInset;
|
-(void) didSetContainerInset:(UIEdgeInsets)textContainerInset;
|
||||||
-(void) didSetTextColor:(UIColor *)textColor;
|
-(void) didSetTextColor:(UIColor *)textColor;
|
||||||
|
-(void) didSetText:(NSString *)text;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -48,7 +52,10 @@
|
|||||||
[self.delegateForUIChange didSetTextColor:textColor];
|
[self.delegateForUIChange didSetTextColor:textColor];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setText:(NSString *)text {
|
||||||
|
[super setText:text];
|
||||||
|
[self.delegateForUIChange didSetText:text];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -72,62 +79,73 @@
|
|||||||
-(void)didSetContainerInset:(UIEdgeInsets)textContainerInset {
|
-(void)didSetContainerInset:(UIEdgeInsets)textContainerInset {
|
||||||
UILabel *placeHolderLabel = self.placeHolderLabel;
|
UILabel *placeHolderLabel = self.placeHolderLabel;
|
||||||
[placeHolderLabel removeConstraints:[self.placeHolderLabel constraints]];
|
[placeHolderLabel removeConstraints:[self.placeHolderLabel constraints]];
|
||||||
|
|
||||||
CGSize labelSize = [placeHolderLabel.text sizeWithAttributes:@{NSFontAttributeName: self.placeHolderLabel.font}];
|
CGSize labelSize = [placeHolderLabel.text sizeWithAttributes:@{NSFontAttributeName: self.placeHolderLabel.font}];
|
||||||
|
|
||||||
NSArray *constrainsApplied = @[@"PH_TRAILING", @"PH_LEADING", @"PH_TOP"];
|
NSArray *constrainsApplied = @[@"PH_TRAILING", @"PH_LEADING", @"PH_TOP"];
|
||||||
|
|
||||||
for (NSLayoutConstraint *constraint in self.constraints) {
|
for (NSLayoutConstraint *constraint in self.constraints) {
|
||||||
if ([constrainsApplied containsObject:constraint.identifier]) {
|
if ([constrainsApplied containsObject:constraint.identifier]) {
|
||||||
[self removeConstraint:constraint];
|
[self removeConstraint:constraint];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[placeHolderLabel addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[placeHolderLabel(height)]" options:0 metrics:@{@"height":@(ceilf(labelSize.height))} views:NSDictionaryOfVariableBindings(placeHolderLabel)]];
|
[placeHolderLabel addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[placeHolderLabel(height)]" options:0 metrics:@{@"height":@(ceilf(labelSize.height))} views:NSDictionaryOfVariableBindings(placeHolderLabel)]];
|
||||||
[placeHolderLabel addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[placeHolderLabel(width)]" options:0 metrics:@{@"width":@(ceilf(labelSize.width))} views:NSDictionaryOfVariableBindings(placeHolderLabel)]];
|
[placeHolderLabel addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[placeHolderLabel(width)]" options:0 metrics:@{@"width":@(ceilf(labelSize.width))} views:NSDictionaryOfVariableBindings(placeHolderLabel)]];
|
||||||
|
|
||||||
NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:placeHolderLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0 constant:(textContainerInset.left + 5)];
|
NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:placeHolderLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1.0 constant:(textContainerInset.left + 5)];
|
||||||
leadingConstraint.identifier = @"PH_LEADING";
|
leadingConstraint.identifier = @"PH_LEADING";
|
||||||
|
|
||||||
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:placeHolderLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:textContainerInset.top];
|
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:placeHolderLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:textContainerInset.top];
|
||||||
topConstraint.identifier = @"PH_TOP";
|
topConstraint.identifier = @"PH_TOP";
|
||||||
|
|
||||||
[NSLayoutConstraint activateConstraints:@[leadingConstraint, topConstraint]];
|
[NSLayoutConstraint activateConstraints:@[leadingConstraint, topConstraint]];
|
||||||
|
|
||||||
[self updateConstraints];
|
[self updateConstraints];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)didSetTextColor:(UIColor *)textColor {
|
-(void)didSetTextColor:(UIColor *)textColor {
|
||||||
// self.placeHolderLabel.textColor = textColor;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)didSetText:(NSString *)text {
|
||||||
|
[self showOrHidePlaceholderForTextView:self.textView];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma Mark UITextView Delegate methods forwarding
|
#pragma Mark UITextView Delegate methods forwarding
|
||||||
|
|
||||||
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView {
|
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView {
|
||||||
return [self.delegate textViewShouldBeginEditing:textView];
|
if ([self.delegate respondsToSelector:@selector(textViewShouldBeginEditing:)]) {
|
||||||
|
return [self.delegate textViewShouldBeginEditing:textView];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)textViewDidBeginEditing:(UITextView *)textView {
|
-(void)textViewDidBeginEditing:(UITextView *)textView {
|
||||||
[self.delegate textViewDidBeginEditing:textView];
|
|
||||||
[self showOrHidePlaceholderForTextView:textView];
|
[self showOrHidePlaceholderForTextView:textView];
|
||||||
|
if ([self.delegate respondsToSelector:@selector(textViewDidBeginEditing:)]) {
|
||||||
|
[self.delegate textViewDidBeginEditing:textView];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
|
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
|
||||||
return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text];
|
if ([self.delegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)]) {
|
||||||
|
return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)textViewDidChange:(UITextView *)textView {
|
-(void)textViewDidChange:(UITextView *)textView {
|
||||||
[self.delegate textViewDidBeginEditing:textView];
|
|
||||||
[self showOrHidePlaceholderForTextView:textView];
|
[self showOrHidePlaceholderForTextView:textView];
|
||||||
|
if ([self.delegate respondsToSelector:@selector(textViewDidChange:)]) {
|
||||||
|
[self.delegate textViewDidChange:textView];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)textViewShouldEndEditing:(UITextView *)textView {
|
-(BOOL)textViewShouldEndEditing:(UITextView *)textView {
|
||||||
return [self.delegate textViewShouldEndEditing:textView];
|
if ([self.delegate respondsToSelector:@selector(textViewShouldEndEditing:)]) {
|
||||||
|
return [self.delegate textViewShouldEndEditing:textView];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)textViewDidEndEditing:(UITextView *)textView {
|
-(void)textViewDidEndEditing:(UITextView *)textView {
|
||||||
[self.delegate textViewDidEndEditing:textView];
|
|
||||||
[self showOrHidePlaceholderForTextView:textView];
|
[self showOrHidePlaceholderForTextView:textView];
|
||||||
|
if ([self.delegate respondsToSelector:@selector(textViewDidEndEditing:)]) {
|
||||||
|
[self.delegate textViewDidEndEditing:textView];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) showOrHidePlaceholderForTextView:(UITextView *) textView {
|
- (void) showOrHidePlaceholderForTextView:(UITextView *) textView {
|
||||||
@ -148,10 +166,8 @@
|
|||||||
view.clipsToBounds = YES;
|
view.clipsToBounds = YES;
|
||||||
view.translatesAutoresizingMaskIntoConstraints = NO;
|
view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
view.layer.cornerRadius = CornerRadiusLarge;
|
view.layer.cornerRadius = CornerRadiusLarge;
|
||||||
|
|
||||||
view.textView.delegateForUIChange = view;
|
view.textView.delegateForUIChange = view;
|
||||||
view.textView.translatesAutoresizingMaskIntoConstraints = NO;
|
view.textView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
|
|
||||||
view.placeHolderLabel.text = placeholder;
|
view.placeHolderLabel.text = placeholder;
|
||||||
view.placeHolderLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
view.placeHolderLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||||
view.placeHolderLabel.textColor = [UIColor mfLightGrayColor];
|
view.placeHolderLabel.textColor = [UIColor mfLightGrayColor];
|
||||||
@ -163,7 +179,51 @@
|
|||||||
view.textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo;
|
view.textView.smartInsertDeleteType = UITextSmartInsertDeleteTypeNo;
|
||||||
}
|
}
|
||||||
[view didSetFont:view.textView.font];
|
[view didSetFont:view.textView.font];
|
||||||
|
view.hideBorder = YES;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - bordered textview
|
||||||
|
- (void)makeBordersForTextView {
|
||||||
|
SeparatorView *bottomLine = [SeparatorView separatorAddToView:self position:SeparatorPositionBot];
|
||||||
|
self.bottomLine = bottomLine;
|
||||||
|
self.placeHolderLabel.font = [MFStyler fontB3];
|
||||||
|
[self.textView setFont:[MFStyler fontB2]];
|
||||||
|
[self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)];
|
||||||
|
[MVMCoreUICommonViewsUtility addDismissToolbarToTextView:self.textView delegate:self.delegate];
|
||||||
|
self.errorShowing = NO;
|
||||||
|
self.hideBorder = NO;
|
||||||
|
[self layoutIfNeeded];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (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 blackColor];
|
||||||
|
}
|
||||||
|
[strokeColor setStroke];
|
||||||
|
[self.borderPath stroke];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)drawRect:(CGRect)rect {
|
||||||
|
[super drawRect:rect];
|
||||||
|
[self.borderPath removeAllPoints];
|
||||||
|
if (!self.hideBorder) {
|
||||||
|
self.layer.cornerRadius = 0;
|
||||||
|
[self addBezierPathForBorders];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user