50 lines
2.1 KiB
Swift
50 lines
2.1 KiB
Swift
//
|
|
// UITextFieldExtensions.swift
|
|
// EZSwiftExtensions
|
|
//
|
|
// Created by Wang Yu on 6/26/16.
|
|
// Copyright © 2016 Goktug Yilmaz. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UITextField {
|
|
/// EZSwiftExtensions: Automatically sets these values: backgroundColor = clearColor, textColor = ThemeNicknameColor, clipsToBounds = true,
|
|
/// textAlignment = Left, userInteractionEnabled = true, editable = false, scrollEnabled = false, font = ThemeFontName, fontsize = 17
|
|
public convenience init(x: CGFloat, y: CGFloat, w: CGFloat, h: CGFloat) {
|
|
self.init(x: x, y: y, w: w, h: h, fontSize: 17)
|
|
}
|
|
|
|
/// EZSwiftExtensions: Automatically sets these values: backgroundColor = clearColor, textColor = ThemeNicknameColor, clipsToBounds = true,
|
|
/// textAlignment = Left, userInteractionEnabled = true, editable = false, scrollEnabled = false, font = ThemeFontName
|
|
public convenience init(x: CGFloat, y: CGFloat, w: CGFloat, h: CGFloat, fontSize: CGFloat) {
|
|
self.init(frame: CGRect(x: x, y: y, width: w, height: h))
|
|
font = UIFont.HelveticaNeue(type: FontType.None, size: fontSize)
|
|
backgroundColor = UIColor.clearColor()
|
|
clipsToBounds = true
|
|
textAlignment = NSTextAlignment.Left
|
|
userInteractionEnabled = true
|
|
}
|
|
|
|
/// EZSE: Add left padding to the text in textfield
|
|
func addLeftTextPadding(blankSize: CGFloat) {
|
|
let leftView = UIView()
|
|
leftView.frame = CGRect(x: 0, y: 0, width: blankSize, height: frame.height)
|
|
self.leftView = leftView
|
|
self.leftViewMode = UITextFieldViewMode.Always
|
|
}
|
|
|
|
/// EZSE: Add a image icon on the left side of the textfield
|
|
func addLeftIcon(image: UIImage?, frame: CGRect, imageSize: CGSize) {
|
|
let leftView = UIView()
|
|
leftView.frame = frame
|
|
let imgView = UIImageView()
|
|
imgView.frame = CGRect(x: frame.width - 8 - imageSize.width, y: (frame.height - imageSize.height) / 2, w: imageSize.width, h: imageSize.height)
|
|
imgView.image = image
|
|
leftView.addSubview(imgView)
|
|
self.leftView = leftView
|
|
self.leftViewMode = UITextFieldViewMode.Always
|
|
}
|
|
|
|
}
|