Last active
August 29, 2015 14:09
-
-
Save ArtFeel/fbb6175e15fa0dadc890 to your computer and use it in GitHub Desktop.
UITextField with bottom border
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MGTextField | |
// Megogo | |
// | |
// Copyright (c) 2013 Megogo.net. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface MGLoginTextField : UITextField | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MGTextField | |
// Megogo | |
// | |
// Copyright (c) 2013 Megogo.net. All rights reserved. | |
// | |
#import "MGTextField.h" | |
@interface MGLoginTextField () | |
@property (nonatomic, strong) UIView * separatorView; | |
@end | |
@implementation MGLoginTextField | |
#pragma mark - Initialization | |
- (id)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if ( self ) { | |
[self postInitialization]; | |
} | |
return self; | |
} | |
- (id)initWithCoder:(NSCoder *)coder { | |
self = [super initWithCoder:coder]; | |
if (self) { | |
[self postInitialization]; | |
} | |
return self; | |
} | |
- (void)awakeFromNib { | |
[super awakeFromNib]; | |
[self postInitialization]; | |
} | |
- (void)postInitialization { | |
self.backgroundColor = [UIColor clearColor]; | |
self.separatorView = [UIView new]; | |
self.separatorView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3]; | |
[self addSubview:self.separatorView]; | |
} | |
#pragma mark - Layout | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
CGFloat height = CGRectGetHeight(self.frame); | |
CGFloat width = CGRectGetWidth(self.frame); | |
CGFloat onePixelHeight = 1.0f / [[UIScreen mainScreen] scale]; | |
self.separatorView.frame = CGRectMake(0, height - 1, width, onePixelHeight); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment