Its as easy as:
textfield.setIcon(UIImage(named: 'PasswordLock'))
To run the example project, clone the repo, and run pod install
from the Example directory first.
IconTextField requires SnapKit
.
IconTextField is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'IconTextField2'
IconTextField
works just like UITextField
, except with currently two extra methods, setIcon
and underline
.
Example:
import IconTextField2
// ...
let passwordTextField = IconTextField(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
// Set the icon
passwordTextField.setIcon(image: UIImage.init(named: "Lock"))
// Add a nice underline
passwordTextField.underline()
Methods:
func setIcon(image:UIImage?, width:CGFloat = 25, padding:CGFloat = 10)
func underline(color:UIColor = UIColor.init(white: 0.85, alpha: 1))
- Width essentially specifies the size of your image, the bigger the width the bigger your image.
- Padding controls the space between your image and the where you type your text
josharnoldjosh, [email protected]
IconTextField is available under the MIT license. See the LICENSE file for more info.