Как изменить цвет фона или textLabel в IASKSpecifierValuesViewController?
Я использую 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
}
}
Как вызвать пользовательский класс IASKSpecifierValuesViewController? Примечание: я использую раскадровку. Я открыт без раскадровочных решений. Спасибо вам, ребята...
2 ответа
Окей, я нашел решение.
Я переопределен для метода 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
}
}
Если честно, сейчас не очень хорошее решение. Что вы можете сделать: используйте метод Swizzling, чтобы переопределить tableView:cellForRowAtIndexPath:
метод. Другой подход заключается в использовании пользовательского представления, когда вы нажимаете IASKSpecifierValuesViewController
подкласс при выборе.
Или вы можете изменить IASK, чтобы добавить обратный вызов в IASKSettingsDelegate
, Это может быть что-то вроде:
- (UITableViewCell*)tableView:(UITableView*)tableView valueCellForSpecifier:(IASKSpecifier*)specifier index:(NSUInteger)index;
Для реализации этого делегат должен быть распространен на IASKSpecifierValuesViewController
который сделал бы обратный вызов, если реализовано.
Кроме того, в качестве более гибкого решения мы могли бы разрешить использование собственного подкласса IASKSpecifierValuesViewController
, возможно, указав IASKViewControllerClass
в файле settings.plist, чтобы переопределить значение по умолчанию IASKSpecifierValuesViewController
,
Я бы приветствовал такой запрос на выдачу! (Я поддерживаю IASK.)