Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. //
  2. // YDSearchBar.swift
  3. // YoutubeDownloader
  4. //
  5. // Created by hx0a1q on 25/07/16.
  6. // Copyright © 2016 Yusuf U. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class YDSearchBar: UISearchBar {
  12.  
  13. lazy var path:UIBezierPath = {
  14. let path = UIBezierPath()
  15. let startLine = CGPoint(x: 0.0, y: 0.0)
  16. let finishLine = CGPoint(x: self.bounds.width, y: 0.0)
  17. path.moveToPoint(startLine)
  18. path.addLineToPoint(finishLine)
  19. return path
  20. }()
  21.  
  22. lazy var shapeLayer: CAShapeLayer = {
  23. let layer = CAShapeLayer()
  24. layer.strokeColor = kRedColor.CGColor
  25. layer.lineWidth = 1.0
  26. layer.path = self.path.CGPath
  27. return layer
  28. }()
  29.  
  30. override init(frame: CGRect) {
  31. super.init(frame: frame)
  32. setupView()
  33. }
  34.  
  35. required init?(coder aDecoder: NSCoder) {
  36. fatalError("Initialize error!")
  37. }
  38.  
  39. func setupView(){
  40. translucent = false
  41. barTintColor = kRedColor
  42. tintColor = .whiteColor()
  43. }
  44.  
  45. func findTextFieldIndex() -> Int?{
  46. let searchBarViews = subviews[0].subviews
  47. for (id, view) in searchBarViews.enumerate(){
  48. if view.isKindOfClass(UITextField){
  49. return id
  50. }
  51. }
  52. return nil
  53. }
  54.  
  55. override func drawRect(rect: CGRect) {
  56. super.drawRect(rect)
  57. let subViews = subviews[0].subviews
  58. if let index = findTextFieldIndex(){
  59. let textField = subViews[index] as! UITextField
  60. textField.backgroundColor = kRedColor
  61. textField.textColor = .lightGrayColor()
  62. }
  63. layer.addSublayer(shapeLayer)
  64. }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement