gpt4 book ai didi

swift - swift 4.1 中的侧边菜单

转载 作者:行者123 更新时间:2023-11-30 11:20:16 25 4
gpt4 key购买 nike

SideMenuHelp?1. 有两件事我需要帮助,一看侧面菜单的按钮,您就会看到它在按钮上显示表格 View Controller

  • 如何删除菜单背景图像中的透明内容

  • 请注意,我都是通过编程方式完成的,没有 Storyboard

  • 类 SideBarView:UIView、UITableViewDelegate、UITableViewDataSource {

    var titleArr = [String]()

    weak var delegate: SidebarViewDelegate?

    override init(frame: CGRect) {
    super.init(frame: frame)

    self.backgroundColor = UIColor(patternImage: UIImage(named: "Rectangle 1473")!)



    //self.backgroundColor=UIColor(red: 54/255, green: 55/255, blue: 56/255, alpha: 1.0)
    self.clipsToBounds=true

    titleArr = ["Maddy Alexander", "Messages", "Contact", "Settings", "History", "Help", "Sign Out"]

    setupViews()


    myTableView.delegate=self
    myTableView.dataSource=self
    myTableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    myTableView.tableFooterView=UIView()
    myTableView.separatorStyle = UITableViewCellSeparatorStyle.none
    myTableView.allowsSelection = true
    myTableView.bounces=false
    myTableView.showsVerticalScrollIndicator=false
    myTableView.backgroundColor = UIColor.clear
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return titleArr.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell=tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    cell.backgroundColor = .clear
    cell.selectionStyle = .none
    if indexPath.row == 0 {
    //cell.backgroundColor=UIColor(red: 77/255, green: 77/255, blue: 77/255, alpha: 1.0)
    let cellImg: UIImageView!
    cellImg = UIImageView(frame: CGRect(x: 15, y: 10, width: 80, height: 80))
    cellImg.layer.cornerRadius = 40
    cellImg.layer.masksToBounds=true
    cellImg.contentMode = .scaleAspectFill
    cellImg.layer.masksToBounds=true
    cellImg.image=#imageLiteral(resourceName: "user2")
    cell.addSubview(cellImg)

    let cellLbl = UILabel(frame: CGRect(x: 110, y: cell.frame.height/2-15, width: 250, height: 30))
    cell.addSubview(cellLbl)
    cellLbl.text = titleArr[indexPath.row]
    cellLbl.font=UIFont.systemFont(ofSize: 17)
    cellLbl.textColor=UIColor.white
    } else {
    cell.textLabel?.text=titleArr[indexPath.row]
    cell.textLabel?.textColor=UIColor.white
    }
    return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    self.delegate?.sidebarDidSelectRow(row: Row(row: indexPath.row))
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == 0 {
    return 100
    } else {
    return 60
    }
    }

    func setupViews() {
    self.addSubview(myTableView)
    myTableView.topAnchor.constraint(equalTo: topAnchor).isActive=true
    myTableView.leftAnchor.constraint(equalTo: leftAnchor).isActive=true
    myTableView.rightAnchor.constraint(equalTo: rightAnchor).isActive=true
    myTableView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive=true
    }

    let myTableView: UITableView = {
    let table=UITableView()
    table.translatesAutoresizingMaskIntoConstraints=false
    return table
    }()

    required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
    }

    }

    最佳答案

    我建议你给 SWRevealController尝试一下,它会为你处理很多事情,所以你不必担心。至于透明度,您可以使用类似 view.alpha = 0.5

    关于swift - swift 4.1 中的侧边菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51335684/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com