Commit f3408e13 by Daniel Dahan

development: added image and title convenience initializer methods to Button class

parent 4f72b9fa
......@@ -84,6 +84,24 @@ open class Button: UIButton {
}
}
/// Sets the normal and highlighted title for the button.
@IBInspectable
open var title: String? {
didSet {
setTitle(title, for: .normal)
setTitle(title, for: .highlighted)
}
}
/// Sets the normal and highlighted titleColor for the button.
@IBInspectable
open var titleColor: UIColor? {
didSet {
setTitleColor(titleColor, for: .normal)
setTitleColor(titleColor, for: .highlighted)
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
......@@ -108,6 +126,46 @@ open class Button: UIButton {
public convenience init() {
self.init(frame: CGRect.zero)
}
/**
A convenience initializer that acceps an image.
- Parameter image: A UIImage.
*/
public convenience init(image: UIImage?) {
self.init()
self.image = image
}
/**
A convenience initializer that acceps an image and tintColor.
- Parameter image: A UIImage.
- Parameter tintColor: A UIColor.
*/
public convenience init(image: UIImage?, tintColor: UIColor?) {
self.init()
self.image = image
self.tintColor = tintColor
}
/**
A convenience initializer that acceps a title.
- Parameter title: A String.
*/
public convenience init(title: String?) {
self.init()
self.title = title
}
/**
A convenience initializer that acceps a title and titleColor.
- Parameter title: A String.
- Parameter titleColor: A UIColor.
*/
public convenience init(title: String?, titleColor: UIColor?) {
self.init()
self.title = title
self.titleColor = titleColor
}
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
......
......@@ -108,11 +108,9 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
*/
open func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool {
if let v = navigationBar as? NavigationBar {
let backButton = IconButton()
let backButton = IconButton(image: v.backButtonImage)
backButton.pulseColor = Color.white
backButton.setImage(v.backButtonImage, for: .normal)
backButton.setImage(v.backButtonImage, for: .highlighted)
backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
if var c = item.leftControls {
c.append(backButton)
......
......@@ -159,12 +159,8 @@ public class SearchBar: BarView {
/// Prepares the clearButton.
private func prepareClearButton() {
let image: UIImage? = Icon.cm.close
clearButton = IconButton()
clearButton = IconButton(image: Icon.cm.close, tintColor: placeholderColor)
clearButton.contentEdgeInsets = UIEdgeInsets.zero
clearButton.tintColor = placeholderColor
clearButton.setImage(image, for: .normal)
clearButton.setImage(image, for: .highlighted)
clearButtonAutoHandleEnabled = true
textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing
......
......@@ -206,14 +206,10 @@ open class TextField: UITextField {
set(value) {
if value {
if nil == clearIconButton {
let image: UIImage? = Icon.cm.clear
clearIconButton = IconButton(frame: CGRect.zero)
clearIconButton = IconButton(image: Icon.cm.clear, tintColor: placeholderColor)
clearIconButton!.contentEdgeInsets = UIEdgeInsets.zero
clearIconButton!.pulseAnimation = .center
clearIconButton!.tintColor = placeholderColor
clearIconButton!.setImage(image, for: .normal)
clearIconButton!.setImage(image, for: .highlighted)
clearButtonMode = .never
clearButtonMode = .never
rightViewMode = .whileEditing
rightView = clearIconButton
clearIconButtonAutoHandle = clearIconButtonAutoHandle ? true : false
......@@ -245,14 +241,9 @@ open class TextField: UITextField {
set(value) {
if value {
if nil == visibilityIconButton {
let image: UIImage? = Icon.visibility
visibilityIconButton = IconButton(frame: CGRect.zero)
visibilityIconButton = IconButton(image: Icon.visibility, tintColor: placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54))
visibilityIconButton!.contentEdgeInsets = UIEdgeInsets.zero
visibilityIconButton!.pulseAnimation = .center
visibilityIconButton!.tintColor = placeholderColor
visibilityIconButton!.setImage(image, for: .normal)
visibilityIconButton!.setImage(image, for: .highlighted)
visibilityIconButton!.tintColor = placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54)
isSecureTextEntry = true
clearButtonMode = .never
rightViewMode = .whileEditing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment