You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改IASKSpecifierValuesViewController背景/文本颜色及调用自定义类?

Got it, let's break this down into two clear parts: first building your custom IASKSpecifierValuesViewController to adjust its appearance, then making your existing SettingsViewController use this custom class instead of the default one. I'll cover both Storyboard and code-based approaches for you.


1. Create Your Custom IASKSpecifierValuesViewController

Just like how you customized IASKAppSettingsViewController, you'll subclass IASKSpecifierValuesViewController to tweak its background, text colors, and other styles. Here's the code:

import UIKit
import InAppSettingsKit

class CustomSpecifierValuesViewController: IASKSpecifierValuesViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Set your desired background color
        view.backgroundColor = .black
        // Optional: Adjust navigation bar styling if needed
        navigationController?.navigationBar.tintColor = .white
        navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = super.tableView(tableView, cellForRowAt: indexPath)
        // Customize cell text and background
        cell.textLabel?.textColor = .white
        cell.detailTextLabel?.textColor = .gray
        cell.backgroundColor = .clear
        cell.selectionStyle = .none
        return cell
    }
    
    // Optional: Customize section headers if your specifiers use them
    override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        guard let headerView = view as? UITableViewHeaderFooterView else { return }
        headerView.textLabel?.textColor = .white
        headerView.contentView.backgroundColor = .darkGray
    }
}

2. Make Your SettingsViewController Use the Custom Values VC

The key here is overriding a method from IASKAppSettingsViewController that creates the values view controller. This works for both Storyboard and code-based setups.

Option A: Code-Based (Non-Storyboard)

Add this override to your existing SettingsViewController:

override func specifierValuesViewController(for specifier: IASKSpecifier) -> IASKSpecifierValuesViewController {
    let customVC = CustomSpecifierValuesViewController(style: .plain)
    customVC.specifier = specifier
    customVC.settingsStore = settingsStore
    return customVC
}

Option B: Storyboard-Based

  1. Open your Storyboard, add a new UITableViewController object.
  2. Set its custom class to CustomSpecifierValuesViewController in the Identity Inspector.
  3. Give it a Storyboard ID (e.g., CustomSpecifierValuesVC) in the Identity Inspector.
  4. Add this override to your SettingsViewController:
override func specifierValuesViewController(for specifier: IASKSpecifier) -> IASKSpecifierValuesViewController {
    // Replace "Main" with your Storyboard's name if it's different
    guard let customVC = UIStoryboard(name: "Main", bundle: nil)
            .instantiateViewController(withIdentifier: "CustomSpecifierValuesVC") as? CustomSpecifierValuesViewController else {
        // Fall back to the default VC if initialization fails
        return super.specifierValuesViewController(for: specifier)
    }
    customVC.specifier = specifier
    customVC.settingsStore = settingsStore
    return customVC
}

Now when users tap a settings item that opens a value picker, your styled CustomSpecifierValuesViewController will appear instead of the default one.


内容的提问来源于stack exchange,提问作者Erkam KUCET

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:58:17