-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor search text field into its own subclass
- Loading branch information
1 parent
8c30732
commit 5aa3379
Showing
4 changed files
with
66 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// SearchTextField.swift | ||
// RealmVideo | ||
// | ||
// Created by Patrick Balestra on 5/10/16. | ||
// Copyright © 2016 Patrick Balestra. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@IBDesignable class SearchTextField: UITextField { | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setUp() | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
super.init(coder: aDecoder) | ||
setUp() | ||
} | ||
|
||
func setUp() { | ||
layer.borderColor = UIColor.whiteColor().CGColor | ||
layer.borderWidth = 1.0 | ||
layer.cornerRadius = 5.0 | ||
tintColor = UIColor.whiteColor() | ||
|
||
let placeholder = NSAttributedString(string: "realm.io/...", attributes: [NSForegroundColorAttributeName : UIColor(white: 1.0, alpha: 0.5)]) | ||
attributedPlaceholder = placeholder | ||
|
||
let clearButton = UIButton(type: .Custom) | ||
clearButton.setImage(UIImage(named: "clear-icon"), forState: .Normal) | ||
clearButton.frame = CGRect(x: 0, y: 0, width: 25.0, height: 15.0) | ||
clearButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) | ||
rightView = clearButton | ||
rightViewMode = .Always | ||
clearButton.addTarget(self, action: #selector(clearTextField), forControlEvents: .TouchUpInside) | ||
} | ||
|
||
func clearTextField() { | ||
text = "" | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters