// // YMHomeSearchView.swift // MvpGoods // // Created by 小花 on 2019/4/12. // Copyright © 2019 MVP. All rights reserved. // import UIKit class YMHomeSearchView: UIView { typealias ClickClosure = () -> Void var clickButton: ClickClosure? required init?(coder aDecoder: NSCoder) { self.init() } override init(frame: CGRect) { super.init(frame: frame) initSubViews() } func initSubViews() { let searchBg = UIView(frame: CGRect(x: 15, y: 0, width: self.width-30, height: self.height)) searchBg.backgroundColor = UIColor.white searchBg.layer.cornerRadius = self.height/2 self.addSubview(searchBg) let searchBtn = UIButton(frame: CGRect(x: 10, y: 0, width: searchBg.width, height: searchBg.height)) searchBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14) searchBtn.setTitleColor(UIColor.hexadecimalColor(hexadecimal: "#666666"), for: .normal) searchBtn.set(image: UIImage(named: "search_gray"), title: "请输入商品名称", titlePosition: .right, additionalSpacing: 5, state: .normal) searchBg.addSubview(searchBtn) searchBtn.addTarget(self, action: #selector(clickAction), for: .touchUpInside) searchBtn.contentHorizontalAlignment = .left } @objc func clickAction() { if (self.clickButton != nil) { self.clickButton!() } } }