Skip to content

Instantly share code, notes, and snippets.

@psobko
Created October 26, 2013 18:53
Show Gist options
  • Save psobko/7173180 to your computer and use it in GitHub Desktop.
Save psobko/7173180 to your computer and use it in GitHub Desktop.
UITextField padding with a custom leftView UIImageView
-(UIView*)paddingViewWithImage:(UIImageView*)imageView andPadding:(float)padding
{
float height = CGRectGetHeight(imageView.frame);
float width = CGRectGetWidth(imageView.frame) + padding;
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
[paddingView addSubview:imageView];
return paddingView;
}
@neen-tech
Copy link

class func textFieldDesignWithLeftPadding(textField:UITextField,color:UIColor,placeHonderName:NSString,placeHolderColor:UIColor, padding:Int, image:UIImage)
{
let viewPadding = UIView(frame: CGRect(x: 0, y: 0, width: padding , height: Int(textField.frame.size.height)))

    let imageView = UIImageView (frame:CGRect(x: 0, y: 0, width: 24 , height: 24))
    
    imageView.center = viewPadding.center
    imageView.image  = image
    viewPadding .addSubview(imageView)
    
    textField.placeholder = placeHonderName as String
    textField.setValue(placeHolderColor, forKeyPath: "_placeholderLabel.textColor")
    textField.leftView = viewPadding
    textField.leftViewMode = .always
    
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment