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 { ...@@ -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. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -108,6 +126,46 @@ open class Button: UIButton { ...@@ -108,6 +126,46 @@ open class Button: UIButton {
public convenience init() { public convenience init() {
self.init(frame: CGRect.zero) 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) { open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer) super.layoutSublayers(of: layer)
......
...@@ -108,11 +108,9 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele ...@@ -108,11 +108,9 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
*/ */
open func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool { open func navigationBar(navigationBar: UINavigationBar, shouldPushItem item: UINavigationItem) -> Bool {
if let v = navigationBar as? NavigationBar { if let v = navigationBar as? NavigationBar {
let backButton = IconButton() let backButton = IconButton(image: v.backButtonImage)
backButton.pulseColor = Color.white backButton.pulseColor = Color.white
backButton.setImage(v.backButtonImage, for: .normal) backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
backButton.setImage(v.backButtonImage, for: .highlighted)
backButton.addTarget(self, action: #selector(handleBackButton), for: .touchUpInside)
if var c = item.leftControls { if var c = item.leftControls {
c.append(backButton) c.append(backButton)
......
...@@ -159,12 +159,8 @@ public class SearchBar: BarView { ...@@ -159,12 +159,8 @@ public class SearchBar: BarView {
/// Prepares the clearButton. /// Prepares the clearButton.
private func prepareClearButton() { private func prepareClearButton() {
let image: UIImage? = Icon.cm.close clearButton = IconButton(image: Icon.cm.close, tintColor: placeholderColor)
clearButton = IconButton()
clearButton.contentEdgeInsets = UIEdgeInsets.zero clearButton.contentEdgeInsets = UIEdgeInsets.zero
clearButton.tintColor = placeholderColor
clearButton.setImage(image, for: .normal)
clearButton.setImage(image, for: .highlighted)
clearButtonAutoHandleEnabled = true clearButtonAutoHandleEnabled = true
textField.clearButtonMode = .never textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing textField.rightViewMode = .whileEditing
......
...@@ -206,14 +206,10 @@ open class TextField: UITextField { ...@@ -206,14 +206,10 @@ open class TextField: UITextField {
set(value) { set(value) {
if value { if value {
if nil == clearIconButton { if nil == clearIconButton {
let image: UIImage? = Icon.cm.clear clearIconButton = IconButton(image: Icon.cm.clear, tintColor: placeholderColor)
clearIconButton = IconButton(frame: CGRect.zero)
clearIconButton!.contentEdgeInsets = UIEdgeInsets.zero clearIconButton!.contentEdgeInsets = UIEdgeInsets.zero
clearIconButton!.pulseAnimation = .center clearIconButton!.pulseAnimation = .center
clearIconButton!.tintColor = placeholderColor clearButtonMode = .never
clearIconButton!.setImage(image, for: .normal)
clearIconButton!.setImage(image, for: .highlighted)
clearButtonMode = .never
rightViewMode = .whileEditing rightViewMode = .whileEditing
rightView = clearIconButton rightView = clearIconButton
clearIconButtonAutoHandle = clearIconButtonAutoHandle ? true : false clearIconButtonAutoHandle = clearIconButtonAutoHandle ? true : false
...@@ -245,14 +241,9 @@ open class TextField: UITextField { ...@@ -245,14 +241,9 @@ open class TextField: UITextField {
set(value) { set(value) {
if value { if value {
if nil == visibilityIconButton { if nil == visibilityIconButton {
let image: UIImage? = Icon.visibility visibilityIconButton = IconButton(image: Icon.visibility, tintColor: placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54))
visibilityIconButton = IconButton(frame: CGRect.zero)
visibilityIconButton!.contentEdgeInsets = UIEdgeInsets.zero visibilityIconButton!.contentEdgeInsets = UIEdgeInsets.zero
visibilityIconButton!.pulseAnimation = .center 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 isSecureTextEntry = true
clearButtonMode = .never clearButtonMode = .never
rightViewMode = .whileEditing 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