简体   繁体   中英

how to change background or textLabel color in IASKSpecifierValuesViewController?

i' m using InAppSettingsKit on my project. i customized IASKAppSettingsViewController But i don't customize IASKSpecifierValuesViewController.

my IASKAppSettingsViewController Custom Class;

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

how do i call the Custom IASKSpecifierValuesViewController class? Note: i'm using storyboard. I'm open in without storyboard solutions. Thank you guys...

Okey, i found a solution.

i'm override to didSlectRowAtIndexPath method.

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

Detail view source code:

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

There's not really a good solution right now, to be honest. What you could do: use method swizzling to override the tableView:cellForRowAtIndexPath: method. Another approach would be to use a custom view where you push your IASKSpecifierValuesViewController subclass when selected.

Or you could modify IASK to add a callback in IASKSettingsDelegate . This could be something like:

- (UITableViewCell*)tableView:(UITableView*)tableView valueCellForSpecifier:(IASKSpecifier*)specifier index:(NSUInteger)index;

To implement this, the delegate would have to be propagated to IASKSpecifierValuesViewController which would do the callback if implemented.

Alternatively, as a more flexible solution we could allow using a custom subclass of IASKSpecifierValuesViewController , potentially by specifying IASKViewControllerClass in the settings.plist to override the default IASKSpecifierValuesViewController .

I'd welcome such a pull request! (I'm the IASK maintainer.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM