BackgroundVC.swift 4.62 KB
//
//  BackgroundVC.swift
//  HDFwear
//
//  Created by yangbin on 2022/4/1.
//

import UIKit

class BackgroundVC: UIViewController {
    @IBOutlet weak var tableView: UITableView!
    let settingArray: [[String]] = [["iPhone", "三星", "华为", "小米", "OPPO", "vivo"], ["iOS", "Android"]]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = LocString("后台保护")
        
        tableView.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 10, right: 0)
        tableView.register(UINib.init(nibName: "SettingCell3", bundle: Bundle.main), forCellReuseIdentifier: "SettingCell3")

        tableView.tableFooterView = UIView(frame: CGRect.zero)
        // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}



extension BackgroundVC: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 30
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = .clear
        let label = UILabel()
        label.font = RegularFont(14)
        label.numberOfLines = 0
        if section == 0 {
            label.text = LocString("系统运行保护权限")
        } else {
            label.text = LocString("APP使用权限")
        }
        view.addSubview(label)
        label.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(12)
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview().offset(5)
        }
        return view
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = .clear
        let label = UILabel()
        label.font = RegularFont(11)
        label.textColor = UIColor.rgbColorFromHex(0xFF0000)
        label.numberOfLines = 0
        if section == 0 {
            label.text = LocString("为了给你提供更加准确稳定的服务,不影响APP和设备正常使用,请你务必打开以上系统!")
        } else {
            label.text = LocString("为了不影响APP和设备正常使用,请你务必同意APP使用权!")
        }
      
        view.addSubview(label)
        label.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(12)
            make.right.equalToSuperview().offset(-30)
            make.top.equalToSuperview().offset(5)
        }
        return view
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 75
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return settingArray.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return settingArray[section].count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SettingCell3", for: indexPath) as! SettingCell3
//        cell.widthLayout.constant = 30
//        cell.setImageView.image = UIImage(named: settingArray[indexPath.section][indexPath.row])
        cell.titleLabel.font = BoldFont(14)
        cell.titleLabel.text = " " + LocString(settingArray[indexPath.section][indexPath.row])
        return cell
        
    }
    

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath)
        cell?.isSelected = false
        let brand = settingArray[indexPath.section][indexPath.row]
        if indexPath.section == 0 {
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "BackgroundProtectionVC") as! BackgroundProtectionVC
            vc.brand = brand
            navigationController?.pushViewController(vc, animated: true)
        } else {
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "PermissionSettingVC") as! PermissionSettingVC
            vc.brand = brand
            vc.permission = "APP使用权限"
            navigationController?.pushViewController(vc, animated: true)
        }
       
    }
    

}