12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- //
- // MerchantsMenuContent.swift
- // xingchuangke
- //
- // Created by Apple on 2021/3/3.
- // Copyright © 2021 Virgil. All rights reserved.
- //
- class MerchantsMenuContent: UIView {
- @IBOutlet weak var backView: UIView!
- var arrDataMj = NSMutableArray()
- var dicModel = NSDictionary()
- var btn = UIButton()
- var str = ""
- var currentTag = 0
- var selectedBtn = UIButton()
- public var callBackForSure: ((NSDictionary)->())?
- var w: CGFloat = 0
- var h: CGFloat = 15
- func returnData( ) {
- for i in 0..<self.arrDataMj.count {
- let dicNew = NSMutableDictionary(dictionary: self.arrDataMj[i] as! NSDictionary)
- let name = (dicNew as NSDictionary).object(forKey: "machineTypeName") as! String
- let button = UIButton(type: .custom)
- button.backgroundColor = .colorWithCustom(r: 241, g: 241, b: 241)
- button.layer.cornerRadius = 3.0
- button.layer.masksToBounds = true
- button.setFontSize(fontSize: 11)
- button.setTitle(name, for: .normal)
- button.setTitleColor(.black, for: .normal)
- button.tag = i
- if i == 0 {
- selectedBtn = button
- }
- button.addTarget(self, action: #selector(rewardClick(sender:)), for: .touchUpInside)
- let length = (backView.frame.size.width-10*3)/2
- button.frame = CGRect(x: 10 + w, y: h, width: length, height: 30)
- //当button的位置超出右侧边缘时换行
- if 10+w+length > backView.frame.size.width {
- w = 0
- h = h + button.frame.size.height + 10
- button.frame = CGRect(x: 10+w, y: h, width: length, height: 30)
- }
- w = button.frame.size.width + button.frame.origin.x
- backView.addSubview(button)
- }
- }
- @objc func rewardClick(sender : UIButton ) {
- self.btn = sender
- sender.isSelected = !sender.isSelected
- selectedBtn.setTitleColor(.black, for: .selected)
- selectedBtn = btn
- selectedBtn.setTitleColor(.red, for: .selected)
- if sender.isSelected {
- self.dicModel = self.arrDataMj[sender.tag] as! NSDictionary
- self.str = self.dicModel["machineTypeName"] as! String
- sender.setTitleColor(.red, for: .selected)
- }
- }
- @IBAction func btnMenuClick(_ sender: Any) {
- let btn = (sender as! UIButton)
- switch btn.tag {
- case 1007: // 重置
- do {
- self.btn.isSelected = false
- self.dicModel = ["machineTypeId": ""]
- }
- break
- case 1008: // 确定
- if callBackForSure != nil{
- callBackForSure!(self.dicModel)
- }
- break
- default: break
- }
- }
- }
|