快速4.1的侧边菜单

时间:2018-07-14 05:51:49

标签: swift xcode

SideMenuHelp? 1.有两件事需要我帮忙,一看侧面菜单的按钮,您会看到它在按钮上显示了表格视图控制器

  1. 如何删除菜单的背景图像中的透明

  2. 请注意,我通过编程方式无需情节提要来完成所有操作

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")
}

}

1 个答案:

答案 0 :(得分:0)

我建议您尝试SWRevealController,它可以为您带来很多帮助,因此您不必担心。 至于透明度,您可以使用诸如view.alpha = 0.5