This is designable textfield and you can covert this code with : http://objectivec2swift.net/
LDTextField.h
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface LDTextField : UITextField
@property (nonatomic) IBInspectable CGFloat bottomBorderHeight;
@property (nonatomic) IBInspectable CGFloat leftViewWidth;
@property (nonatomic) IBInspectable UIColor *bottomBorderColor;
@property (nonatomic) IBInspectable UIColor *placeHolderColor;
@property (nonatomic) IBInspectable UIImage *leftImage;
@property (nonatomic,retain) UIImageView *imageview;
@property (nonatomic,retain) UIView *bottomview;
@end
LDTextField.m
#import "LDTextField.h"
@implementation LDTextField
-(instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
-(void)drawRect:(CGRect)rect{
if (self.bottomview) {
self.bottomview.frame = CGRectOffset(rect, 0, rect.size.height - self.bottomBorderHeight);
}
}
-(void)setLeftImage:(UIImage *)leftImage{
_leftImage = leftImage;
if (!self.imageview && leftImage.scale > 0) {
self.imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.leftViewWidth, self.frame.size.height)];
}
if (leftImage) {
self.imageview.image = leftImage;
self.imageview.contentMode = UIViewContentModeCenter;
self.leftViewMode = UITextFieldViewModeAlways;
self.leftView = self.imageview;
}
else {
self.imageview.image = leftImage;
self.leftViewMode = UITextFieldViewModeAlways;
self.leftView = self.imageview;
}
}
-(void)setBottomBorderColor:(UIColor *)bottomBorderColor{
_bottomBorderColor = bottomBorderColor;
if (!self.bottomview) {
self.bottomview = [[UIView alloc] initWithFrame:CGRectOffset(self.frame, 0, self.frame.size.height - self.bottomBorderHeight)];
[self addSubview:self.bottomview];
}
self.bottomview.backgroundColor = bottomBorderColor;
}
-(void)setBottomBorderHeight:(CGFloat)bottomBorderHeight
{
_bottomBorderHeight = bottomBorderHeight;
if (!self.bottomview) {
self.bottomview = [[UIView alloc] initWithFrame:CGRectOffset(self.frame, 0, self.frame.size.height - self.bottomBorderHeight)];
[self addSubview:self.bottomview];
}
else{
self.bottomview.frame = CGRectOffset(self.frame, 0, self.frame.size.height - self.bottomBorderHeight);
}
}
-(void)setLeftViewWidth:(CGFloat)leftViewWidth{
_leftViewWidth = leftViewWidth;
if (self.imageview) {
self.imageview.frame = CGRectMake(0, 0, leftViewWidth, self.frame.size.height);
}
}
-(void)setPlaceHolderColor:(UIColor *)placeHolderColor{
_placeHolderColor = placeHolderColor;
if ([self respondsToSelector:@selector(attributedPlaceholder)]) {
@try {
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName: placeHolderColor}];
}
@catch (NSException *exception) {
}
}
}
@end