Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // YDSearchBar.swift
- // YoutubeDownloader
- //
- // Created by hx0a1q on 25/07/16.
- // Copyright © 2016 Yusuf U. All rights reserved.
- //
- import UIKit
- class YDSearchBar: UISearchBar {
- lazy var path:UIBezierPath = {
- let path = UIBezierPath()
- let startLine = CGPoint(x: 0.0, y: 0.0)
- let finishLine = CGPoint(x: self.bounds.width, y: 0.0)
- path.moveToPoint(startLine)
- path.addLineToPoint(finishLine)
- return path
- }()
- lazy var shapeLayer: CAShapeLayer = {
- let layer = CAShapeLayer()
- layer.strokeColor = kRedColor.CGColor
- layer.lineWidth = 1.0
- layer.path = self.path.CGPath
- return layer
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupView()
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("Initialize error!")
- }
- func setupView(){
- translucent = false
- barTintColor = kRedColor
- tintColor = .whiteColor()
- }
- func findTextFieldIndex() -> Int?{
- let searchBarViews = subviews[0].subviews
- for (id, view) in searchBarViews.enumerate(){
- if view.isKindOfClass(UITextField){
- return id
- }
- }
- return nil
- }
- override func drawRect(rect: CGRect) {
- super.drawRect(rect)
- let subViews = subviews[0].subviews
- if let index = findTextFieldIndex(){
- let textField = subViews[index] as! UITextField
- textField.backgroundColor = kRedColor
- textField.textColor = .lightGrayColor()
- }
- layer.addSublayer(shapeLayer)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement