如何在IASKSpecifierValuesViewController中更改background或textLabel颜色?

时间:2018-05-10 13:55:20

标签: ios swift uikit settings inappsettingskit

我'我在我的项目中使用InAppSettingsKit。 我自定义了IASKAppSettingsViewController但我没有自定义IASKSpecifierValuesViewController。

我的IASKAppSettingsViewController自定义类;

import UIKit

class SettingsViewController: IASKAppSettingsViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

  }

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = super.tableView(tableView, cellForRowAt: indexPath)
    cell.backgroundColor = .clear
    cell.textLabel?.textColor = .white
    cell.detailTextLabel?.textColor = .gray
    cell.selectionStyle = .none

    return cell
  }
}

如何调用Custom IASKSpecifierValuesViewController类? 注意:我使用的是故事板。我在没有故事板解决方案的情况下开放。谢谢你们......

1 个答案:

答案 0 :(得分:1)

哦,我找到了解决方案。

我覆盖了didSlectRowAtIndexPath方法。

import UIKit

class SettingsViewController: IASKAppSettingsViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    self.tableView.backgroundColor = .black

  }

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = super.tableView(tableView, cellForRowAt: indexPath)
    cell.backgroundColor = .clear
    cell.textLabel?.textColor = .white
    cell.selectionStyle = .none

    return cell
  }

  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    //Creating specifier object
    let specifier = self.settingsReader.specifier(for: indexPath)
    //Creating a custom IASKSpecifierValuesViewController instance
    let targetViewController = SettingsDetail(style: .grouped)
    targetViewController.currentSpecifier = specifier
    targetViewController.settingsStore = settingsStore
    targetViewController.settingsReader = settingsReader
    self.navigationController?.pushViewController(targetViewController, animated: true)
  }
}

详细信息视图源代码:

import UIKit

class SettingsDetail: IASKSpecifierValuesViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    self.tableView.backgroundColor = .black
  }

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = super.tableView(tableView, cellForRowAt: indexPath)
    cell.backgroundColor = .clear
    cell.textLabel?.textColor = .white
    cell.selectionStyle = .none

    return cell
  }
}
相关问题