Skip to content

Instantly share code, notes, and snippets.

@ArtFeel
Last active August 29, 2015 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArtFeel/fbb6175e15fa0dadc890 to your computer and use it in GitHub Desktop.
Save ArtFeel/fbb6175e15fa0dadc890 to your computer and use it in GitHub Desktop.
UITextField with bottom border
//
// MGTextField
// Megogo
//
// Copyright (c) 2013 Megogo.net. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface MGLoginTextField : UITextField
@end
//
// 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