Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  RIDBottomBorderedTextField.m
  3. //  RamblerIDSDK
  4. //
  5. //  Created by s.sarkisyan on 26.02.17.
  6. //  Copyright © 2017 Rambler&Co. All rights reserved.
  7. //
  8.  
  9. #import "RIDBottomBorderedTextField.h"
  10.  
  11. static CGFloat const kDefalutBottomBorderRGBValue = 213.0f;
  12. static CGFloat const kDefalutRGBMaxValue = 255.0f;
  13. static CGFloat const kDefaultborderHeight = 1.0f;
  14.  
  15. @interface RIDBottomBorderedTextField ()
  16.  
  17. @property (nonatomic, strong, nullable) UIView *bottomBorderView;
  18.  
  19. @end
  20.  
  21. @implementation RIDBottomBorderedTextField
  22.  
  23. - (instancetype)initWithFrame:(CGRect)frame {
  24.     self = [super initWithFrame:frame];
  25.  
  26.     if (self) {
  27.         _borderHeight = kDefaultborderHeight;
  28.        
  29.         _borderColor = [UIColor colorWithRed:kDefalutBottomBorderRGBValue/kDefalutRGBMaxValue
  30.                                        green:kDefalutBottomBorderRGBValue/kDefalutRGBMaxValue
  31.                                         blue:kDefalutBottomBorderRGBValue/kDefalutRGBMaxValue alpha:1.0f];
  32.         [_borderColor setFill];
  33.        
  34.         [self addBottomViewIfNeeded];
  35.     }
  36.    
  37.     return self;
  38. }
  39.  
  40. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  41.     self = [super initWithCoder:aDecoder];
  42.    
  43.     if (self) {
  44.         [self addBottomViewIfNeeded];
  45.     }
  46.    
  47.     return self;
  48. }
  49.  
  50. - (void)prepareForInterfaceBuilder {
  51.     [super prepareForInterfaceBuilder];
  52.    
  53.     [self addBottomView];
  54. }
  55.  
  56. - (void)drawRect:(CGRect)rect {
  57.     [super drawRect:rect];
  58.    
  59.     [self addBottomViewIfNeeded];
  60. }
  61.  
  62. - (void)addBottomViewIfNeeded {
  63.     if (!_bottomBorderView) {
  64.         [self addBottomView];
  65.     }
  66. }
  67.  
  68. - (void)addBottomView {
  69.     if (_borderHeight > 0) {
  70.         CGRect bottomViewFrame;
  71.         bottomViewFrame.origin.x = 0.0f;
  72.         bottomViewFrame.origin.y = self.bounds.size.height - _borderHeight;
  73.         bottomViewFrame.size.width = self.bounds.size.width;
  74.         bottomViewFrame.size.height = _borderHeight;
  75.        
  76.         _bottomBorderView = [[UIView alloc] initWithFrame:bottomViewFrame];
  77.         _bottomBorderView.backgroundColor = _borderColor;
  78.         [self addSubview:_bottomBorderView];
  79.     }
  80. }
  81.  
  82. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement