我如何在节的左侧实现UITableView标头?

问题描述 投票:-1回答:1

我已经通过以下代码添加了图像,但无法达到期望的效果:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 50))
        let image = UIImageView(frame: CGRect(x: 15, y: 10, width: 30, height: 30))

        let section = self.sections[section]

        switch section {
        case .phone:
            image.image = UIImage(systemName: "phone.fill")
            break
        case .mail:
            image.image = UIImage(systemName: "message.fill")
            break
        case .company:
            image.image = UIImage(systemName: "person.fill")
            break
        }
        view.addSubview(image)
        return view
    }

我想要实现的演示

“我想实现的演示”>

我已经通过以下代码添加了图像,但无法按需实现:func tableView(_ tableView:UITableView,viewForHeaderInSection部分:Int)-> UIView? {let view = UIView(...

ios swift xcode uitableview uitableviewsectionheader
1个回答
0
投票

使用节标题无法实现此行为。我建议两个选择,

© www.soinside.com 2019 - 2024. All rights reserved.