Сгруппированный UITableView с радиусом тени и угла? - PullRequest
0 голосов
/ 22 марта 2019

Мне было интересно, как можно создать сгруппированный UITableView с разделами, которые имеют тень и закругленные углы.Кроме того, заголовок раздела можно выбрать, поэтому, когда пользователь щелкает заголовок, ячейки в этом разделе должны свернуться;следовательно, тени и закругленные углы должны будут измениться на новый размер раздела, только заголовок.Кто-нибудь знает, как делать то, о чем я говорю?Я приложил макет пользовательского интерфейса для справки, а также некоторый код.

Вот макет пользовательского интерфейса, который я хочу разработать: UI Design Mockup

Этокод, который я должен настроить tableView:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if section == 0 {
        return nil
    } else if settings[section - 1].isEmpty == false {
        let headerView = Bundle.main.loadNibNamed("HeaderTableViewCell", owner: self, options: nil)?.first as! HeaderTableViewCell

        let settingCategories = ["Account", "Notifications", "Personalized Feed", "Color Theme"]

        headerView.settingCategoryTitle.text = settingCategories[section - 1]

        let totalCellHeight = CGFloat(settings[section - 1].count * 63)
        let height = headerView.frame.height + totalCellHeight

        print("Needed Height: \(height)")

        headerView.clipsToBounds = false
        headerView.headerBackground.frame.size.height = height



        print("HeaderView Height: \(headerView.headerBackground.frame.size.height)")

        headerView.headerBackground.layer.shadowRadius = 10
        headerView.headerBackground.layer.shadowOffset = CGSize(width: 0, height: 1)
        headerView.headerBackground.layer.shadowColor = UIColor.black.cgColor
        headerView.headerBackground.layer.shadowOpacity = 0.1
        headerView.headerBackground.backgroundColor = UIColor(named: "Background")
        headerView.headerBackground.layer.cornerRadius = 10

        headerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleDropDown)))

        return headerView
    } else {
        return nil
    }
}

@objc func handleDropDown() {
    print("Handle Drop Down")
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    if section == 0 {
        return 0.0001
    } else {
        return 54
    }
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    if section == 0 {
        return 10
    } else {
        return 20
    }
}


func numberOfSections(in tableView: UITableView) -> Int {
    return settings.count + 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if section == 0 {
        return 1
    } else {
        return settings[section - 1].count
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if indexPath.section == 0 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SettingTitleCell", for: indexPath) as! SettingsTitleTableViewCell

        cell.titleLabel.text = "Settings"

        return cell
    } else {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SettingCell", for: indexPath) as! SettingTableViewCell

        cell.setSetting(setting: settings[indexPath.section - 1][indexPath.row])
        print("Index Path: \(indexPath.row) SettingCount: \(settings[indexPath.section - 1].count)")


        return cell
    }

}

Этот код дает такой результат: Current Result

Я хотел бы получить помощь о том, как сделать эту работукак я показал в дизайне.Заранее спасибо за любую помощь.

1 Ответ

0 голосов
/ 22 марта 2019

Для свертывания вашего заголовка вы можете использовать это: https://github.com/jeantimex/ios-swift-collapsible-table-section

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...