spaces, spearator map

This commit is contained in:
Ajai Prabhu G S 2019-02-12 20:34:42 +05:30
parent 6958692865
commit f8c4253b39
2 changed files with 8 additions and 34 deletions

View File

@ -31,7 +31,6 @@
@property (nonatomic, readwrite) BOOL errorShowing; @property (nonatomic, readwrite) BOOL errorShowing;
@property (weak, nonatomic, nullable) SeparatorView *bottomLine; @property (weak, nonatomic, nullable) SeparatorView *bottomLine;
+(MFTextView *_Nullable) MFTextViewWithPlaceholderString:(NSString *_Nullable) placeholder delegate:(id _Nullable ) delegate; +(MFTextView *_Nullable) MFTextViewWithPlaceholderString:(NSString *_Nullable) placeholder delegate:(id _Nullable ) delegate;
//This method will make the UI as per brand refresh (Similar to UITextField) //This method will make the UI as per brand refresh (Similar to UITextField)

View File

@ -57,8 +57,6 @@
[self.delegateForUIChange didSetText:text]; [self.delegateForUIChange didSetText:text];
} }
@end @end
@interface MFTextView () <CustomTextViewDelegate> @interface MFTextView () <CustomTextViewDelegate>
@ -81,33 +79,25 @@
-(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 { - (void)didSetText:(NSString *)text {
@ -124,18 +114,15 @@
} }
-(void)textViewDidBeginEditing:(UITextView *)textView { -(void)textViewDidBeginEditing:(UITextView *)textView {
[self showOrHidePlaceholderForTextView:textView]; [self showOrHidePlaceholderForTextView:textView];
if ([self.delegate respondsToSelector:@selector(textViewDidBeginEditing:)]) { if ([self.delegate respondsToSelector:@selector(textViewDidBeginEditing:)]) {
[self.delegate textViewDidBeginEditing:textView]; [self.delegate textViewDidBeginEditing:textView];
} }
} }
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([self.delegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)]) { if ([self.delegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)]) {
return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text]; return [self.delegate textView:textView shouldChangeTextInRange:range replacementText:text];
} }
return true; return true;
} }
@ -144,15 +131,12 @@
[self showOrHidePlaceholderForTextView:textView]; [self showOrHidePlaceholderForTextView:textView];
if ([self.delegate respondsToSelector:@selector(textViewDidChange:)]) { if ([self.delegate respondsToSelector:@selector(textViewDidChange:)]) {
[self.delegate textViewDidChange:textView]; [self.delegate textViewDidChange:textView];
} }
} }
-(BOOL)textViewShouldEndEditing:(UITextView *)textView { -(BOOL)textViewShouldEndEditing:(UITextView *)textView {
if ([self.delegate respondsToSelector:@selector(textViewShouldEndEditing:)]) { if ([self.delegate respondsToSelector:@selector(textViewShouldEndEditing:)]) {
return [self.delegate textViewShouldEndEditing:textView]; return [self.delegate textViewShouldEndEditing:textView];
} }
return true; return true;
} }
@ -161,10 +145,7 @@
[self showOrHidePlaceholderForTextView:textView]; [self showOrHidePlaceholderForTextView:textView];
if ([self.delegate respondsToSelector:@selector(textViewDidEndEditing:)]) { if ([self.delegate respondsToSelector:@selector(textViewDidEndEditing:)]) {
[self.delegate textViewDidEndEditing:textView]; [self.delegate textViewDidEndEditing:textView];
} }
} }
- (void) showOrHidePlaceholderForTextView:(UITextView *) textView { - (void) showOrHidePlaceholderForTextView:(UITextView *) textView {
@ -185,14 +166,12 @@
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];
// Disable SmartQuotes // Disable SmartQuotes
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
view.textView.smartQuotesType = UITextSmartQuotesTypeNo; view.textView.smartQuotesType = UITextSmartQuotesTypeNo;
@ -204,11 +183,10 @@
return view; return view;
} }
#pragma mark - bordered textview #pragma mark - bordered textview
- (void)makeBordersForTextView { - (void)makeBordersForTextView {
SeparatorView *bottomLine = [SeparatorView separatorAddToView:self position:SeparatorPositionBot];
[SeparatorView separatorAddToView:self position:SeparatorPositionBot]; self.bottomLine = bottomLine;
self.placeHolderLabel.font = [MFStyler fontB3]; self.placeHolderLabel.font = [MFStyler fontB3];
[self.textView setFont:[MFStyler fontB2]]; [self.textView setFont:[MFStyler fontB2]];
[self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)]; [self.textView setTextContainerInset:UIEdgeInsetsMake(PaddingTwo, PaddingTwo, PaddingTwo, PaddingOne)];
@ -225,7 +203,6 @@
[self.borderPath addLineToPoint:CGPointMake(frame.origin.x, frame.origin.y)]; [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)];
[self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)]; [self.borderPath addLineToPoint:CGPointMake(frame.origin.x + frame.size.width, frame.origin.y + frame.size.height)];
self.borderPath.lineWidth = 1; self.borderPath.lineWidth = 1;
UIColor *strokeColor; UIColor *strokeColor;
@ -234,11 +211,9 @@
self.bottomLine.backgroundColor = [UIColor mfPumpkinColor]; self.bottomLine.backgroundColor = [UIColor mfPumpkinColor];
} else { } else {
strokeColor = [UIColor mfSilver]; strokeColor = [UIColor mfSilver];
self.bottomLine.backgroundColor = [UIColor mfSilver]; self.bottomLine.backgroundColor = [UIColor blackColor];
} }
[strokeColor setStroke]; [strokeColor setStroke];
[self.borderPath stroke]; [self.borderPath stroke];
} }
@ -246,7 +221,7 @@
[super drawRect:rect]; [super drawRect:rect];
[self.borderPath removeAllPoints]; [self.borderPath removeAllPoints];
if (!self.hideBorder) { if (!self.hideBorder) {
self.layer.cornerRadius = 0; self.layer.cornerRadius = 0;
[self addBezierPathForBorders]; [self addBezierPathForBorders];
} }
} }