12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- // IHAreaItem.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/26.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- fileprivate class IHAreaItemButton: UIButton {
- override func layoutSubviews() {
- super.layoutSubviews()
- let titleLabelFrame = titleLabel?.frame
- let imageViewFrame = imageView?.frame
- let totleWidth = (titleLabelFrame?.size.width)! + (imageViewFrame?.size.width)! + 2
- titleLabel?.frame.origin.x = ( self.frame.size.width - totleWidth ) / 2
- imageView?.frame.origin.x = (titleLabel?.frame.origin.x)! + (titleLabelFrame?.size.width)! + 2
-
- }
- }
- class IHAreaItem: UIView {
- var defaultDesc:String?{
- didSet{
- if let desc = self.defaultDesc {
- button.setTitle(desc, for: .normal)
- }
- }
- }
-
- var titleArray :[String]?{
- didSet{
- buttonTitle = self.titleArray?.first
- }
- }
-
- var confirmBlock:((Int)->Void)?
-
- private var buttonTitle : String?{
- didSet{
- if let buttonTitle = self.buttonTitle {
- button.setTitle(buttonTitle, for: .normal)
- }
- }
- }
-
- private lazy var button: IHAreaItemButton = {
- let btn = IHAreaItemButton(type: .custom)
- btn.setImage(UIImage(named: "itemxiala"), for: .normal)
- btn.setTitle("Building", for: .normal)
- btn.setTitleColor(UIColor(hexString: "333333"), for: .normal)
- btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 13)
- btn.addTarget(self, action: #selector(btnClick), for: .touchUpInside)
- return btn
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
- self.backgroundColor = UIColor(hexString: "#F6F8FA")
-
- createUI()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- @objc private func btnClick(sennder: UIButton) {
- if self.titleArray?.count == 0 {
- g_showHUD("无数据!")
- button.setTitle("Building", for: .normal)
- return
- }
- let pick = THScrollChooseView(question: self.titleArray, withDefaultDesc: self.defaultDesc ?? self.titleArray?.first)
- pick?.confirmBlock = {(selectedIndex) in
- log.debug(" title = \(self.titleArray?[selectedIndex])")
- let title = self.titleArray?[selectedIndex]
- self.buttonTitle = title
- if let confirm = self.confirmBlock {
- confirm(selectedIndex)
- }
- }
-
- pick?.show()
- }
-
- func createUI() {
- let line = UIView(frame: CGRect(x: self.width - 1, y: 8, width: 1, height: 17))
- line.backgroundColor = UIColor(hexString: "E2E2E2")
- addSubview(line)
- button.frame = CGRect(x: 0, y: 0, width: self.width - 1, height: self.height)
- addSubview(button)
- }
- }
|