123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- //
- // IHRoomHistoryToolBar.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/17.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- protocol IHRoomHistoryToolBarDelegate : NSObjectProtocol {
- func roomHistorydidSelectedLeftBarItem(at index:Int)
- func roomHistorydidSelectedRightBarItem(at index:Int)
- }
- class IHRoomHistoryToolBar: UIView {
- var currentDateType:Int? = 0{
- didSet{
- if let dateType = self.currentDateType {
- for i in 0..<titles.count {
- let btn = viewWithTag(1400 + i) as! UIButton
- if i == dateType {
- btn.isSelected = true
- // #05CFAB
- btn.backgroundColor = UIColor(hexString: "#573F95")
- }else{
- btn.isSelected = false
- btn.backgroundColor = UIColor(hexString: "#F6F8F7")
- }
-
- }
-
- }
- }
- }
- var devType:String? = "1"{
- didSet{
- if let devType = self.devType {
- if devType == "1" || devType == "2" || devType == "4" {
- titles = ["当天","本周","当月","当年","自定义"]
- }else{
- titles = ["当天","本周","当月","当年"]
- }
- configRightBar()
- }
- }
- }
- var titles : [String] = ["当天","本周","当月","当年"]
- weak var delegate: IHRoomHistoryToolBarDelegate?
- override init(frame: CGRect) {
- super.init(frame: frame)
- configLeftBar()
-
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func configLeftBar() {
- for i in 0..<2 {
- let button = UIButton(type: .custom)
- button.frame = CGRect(x:Double( 20 + i * 35), y: 14.5, width: 35, height: 23)
- button.tag = 1300 + i
- button.backgroundColor = UIColor(hexString: "#F6F8F7")
- button.layer.cornerRadius = 3
- button.layer.masksToBounds = true
- if i == 0 {
- button.setImage(UIImage(named: "折线图_未选中"), for: .normal)
- button.setImage(UIImage(named: "折线图_选中"), for: .normal)
- }else {
- button.setImage(UIImage(named: "柱状图_未选中"), for: .normal)
- button.setImage(UIImage(named: "柱状图_选中"), for: .normal)
- }
-
- if i == self.currentDateType {
- button.isSelected = true
- button.backgroundColor = UIColor(hexString: "#573F95")
- }
-
- button.addTarget(self, action: #selector(selectedLeftAction), for: .touchUpInside)
- addSubview(button)
- }
- }
-
- func configRightBar() {
-
- let width = (KSCREENWIDTH - 110 - 36 ) / CGFloat(titles.count)
- for i in 0..<titles.count {
- let button = UIButton(type: .custom)
- button.frame = CGRect(x: 110 + CGFloat(i) * width, y: 14.5, width: width + 1, height: 23)
- button.tag = 1400 + i
- button.backgroundColor = UIColor(hexString: "#F6F8F7")
- button.layer.cornerRadius = 3
- button.layer.masksToBounds = true
- button.setTitle(titles[i], for: .normal)
- button.titleLabel?.font = UIFont(name: Alibaba_PuHuiTi_Regular, size: 12)
- button.setTitleColor(UIColor(hexString: "#657085"), for: .normal)
- button.setTitleColor(UIColor(hexString: "#FFFFFF"), for: .selected)
- if i == 0 {
- button.isSelected = true
- button.backgroundColor = UIColor(hexString: "#573F95")
- button.titleLabel?.font = UIFont(name: Alibaba_PuHuiTi_Medium, size: 12)
- }
- button.addTarget(self, action: #selector(selectedRightAction), for: .touchUpInside)
- addSubview(button)
- }
- }
-
- @objc func selectedLeftAction(_ sender:UIButton) {
- for i in 0..<2 {
- let btn = viewWithTag(1300 + i) as! UIButton
- btn.isSelected = false
- btn.backgroundColor = UIColor(hexString: "#F6F8F7")
- }
- sender.isSelected = true
- sender.backgroundColor = UIColor(hexString: "#573F95")
-
- if let delegate = delegate {
- delegate.roomHistorydidSelectedLeftBarItem(at: sender.tag - 1300)
- }
- }
-
- @objc func selectedRightAction(_ sender:UIButton) {
- for i in 0..<titles.count {
- let btn = viewWithTag(1400 + i) as! UIButton
- btn.isSelected = false
- //#573F95 "#F6F8F7
- //
- btn.backgroundColor = UIColor(hexString: "#F6F8F7")
- btn.titleLabel?.font = UIFont(name: Alibaba_PuHuiTi_Regular, size: 12)
-
- }
- sender.isSelected = true
- sender.backgroundColor = UIColor(hexString: "#573F95")
- sender.titleLabel?.font = UIFont(name: Alibaba_PuHuiTi_Medium, size: 12)
-
- if let delegate = delegate {
- delegate.roomHistorydidSelectedRightBarItem(at: sender.tag - 1400)
- }
-
- }
- }
|