Last active
February 15, 2018 20:45
-
-
Save jkereako/dc715c95f381797bcbfec188178b7ff2 to your computer and use it in GitHub Desktop.
Demonstrates how to add a bottom border to a UITextField.
This file contains hidden or 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
import UIKit | |
import PlaygroundSupport | |
//-- Container view | |
let container = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 500)) | |
container.backgroundColor = .darkGray | |
//-- Textfield | |
let textField = UITextField(frame: CGRect(x: 0, y: 0, width: container.bounds.width, height: 50)) | |
textField.text = "There once was a man from Nantucket..." | |
textField.borderStyle = .none | |
textField.backgroundColor = .blue | |
textField.textColor = .white | |
textField.layer.masksToBounds = true | |
//-- Border | |
let borderWidth: CGFloat = 3 | |
let borderLayer = CALayer(); | |
borderLayer.frame = CGRect( | |
x: 0, | |
y: textField.frame.height - borderWidth, | |
width: textField.frame.width, | |
height: borderWidth | |
) | |
borderLayer.borderWidth = borderWidth | |
borderLayer.borderColor = UIColor.yellow.cgColor | |
//-- Add layers and subviews | |
textField.layer.addSublayer(borderLayer) | |
container.addSubview(textField) | |
//-- Playground boilerplate | |
PlaygroundPage.current.liveView = container | |
PlaygroundPage.current.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment