优惠券swift版马甲包

YMHomeSearchView.swift 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // YMHomeSearchView.swift
  3. // MvpGoods
  4. //
  5. // Created by 小花 on 2019/4/12.
  6. // Copyright © 2019 MVP. All rights reserved.
  7. //
  8. import UIKit
  9. class YMHomeSearchView: UIView {
  10. typealias ClickClosure = () -> Void
  11. var clickButton: ClickClosure?
  12. required init?(coder aDecoder: NSCoder) {
  13. self.init()
  14. }
  15. override init(frame: CGRect) {
  16. super.init(frame: frame)
  17. initSubViews()
  18. }
  19. func initSubViews() {
  20. let searchBg = UIView(frame: CGRect(x: 15, y: 0, width: self.width-30, height: self.height))
  21. searchBg.backgroundColor = UIColor.white
  22. searchBg.layer.cornerRadius = self.height/2
  23. self.addSubview(searchBg)
  24. let searchBtn = UIButton(frame: CGRect(x: 10, y: 0, width: searchBg.width, height: searchBg.height))
  25. searchBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
  26. searchBtn.setTitleColor(UIColor.hexadecimalColor(hexadecimal: "#666666"), for: .normal)
  27. searchBtn.set(image: UIImage(named: "search_gray"), title: "请输入商品名称", titlePosition: .right, additionalSpacing: 5, state: .normal)
  28. searchBg.addSubview(searchBtn)
  29. searchBtn.addTarget(self, action: #selector(clickAction), for: .touchUpInside)
  30. searchBtn.contentHorizontalAlignment = .left
  31. }
  32. @objc func clickAction() {
  33. if (self.clickButton != nil) {
  34. self.clickButton!()
  35. }
  36. }
  37. }