Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // RIDBottomBorderedTextField.m
- // RamblerIDSDK
- //
- // Created by s.sarkisyan on 26.02.17.
- // Copyright © 2017 Rambler&Co. All rights reserved.
- //
- #import "RIDBottomBorderedTextField.h"
- static CGFloat const kDefalutBottomBorderRGBValue = 213.0f;
- static CGFloat const kDefalutRGBMaxValue = 255.0f;
- static CGFloat const kDefaultborderHeight = 1.0f;
- @interface RIDBottomBorderedTextField ()
- @property (nonatomic, strong, nullable) UIView *bottomBorderView;
- @end
- @implementation RIDBottomBorderedTextField
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- _borderHeight = kDefaultborderHeight;
- _borderColor = [UIColor colorWithRed:kDefalutBottomBorderRGBValue/kDefalutRGBMaxValue
- green:kDefalutBottomBorderRGBValue/kDefalutRGBMaxValue
- blue:kDefalutBottomBorderRGBValue/kDefalutRGBMaxValue alpha:1.0f];
- [_borderColor setFill];
- [self addBottomViewIfNeeded];
- }
- return self;
- }
- - (instancetype)initWithCoder:(NSCoder *)aDecoder {
- self = [super initWithCoder:aDecoder];
- if (self) {
- [self addBottomViewIfNeeded];
- }
- return self;
- }
- - (void)prepareForInterfaceBuilder {
- [super prepareForInterfaceBuilder];
- [self addBottomView];
- }
- - (void)drawRect:(CGRect)rect {
- [super drawRect:rect];
- [self addBottomViewIfNeeded];
- }
- - (void)addBottomViewIfNeeded {
- if (!_bottomBorderView) {
- [self addBottomView];
- }
- }
- - (void)addBottomView {
- if (_borderHeight > 0) {
- CGRect bottomViewFrame;
- bottomViewFrame.origin.x = 0.0f;
- bottomViewFrame.origin.y = self.bounds.size.height - _borderHeight;
- bottomViewFrame.size.width = self.bounds.size.width;
- bottomViewFrame.size.height = _borderHeight;
- _bottomBorderView = [[UIView alloc] initWithFrame:bottomViewFrame];
- _bottomBorderView.backgroundColor = _borderColor;
- [self addSubview:_bottomBorderView];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement