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

Swift/iOS中如何让UIColorPickerViewController仅显示网格标签

需求可行性说明

该需求可以实现,无需调用私有API,苹果官方在UIColorPickerViewController的公开接口中已经提供了对应配置能力,完全符合App Store审核规则。

实现逻辑

UIColorPickerViewController的supportedColorPickers属性用于控制底部展示的标签类型,该属性为数组类型,仅在数组中添加网格色卡对应的枚举值,即可隐藏其余所有标签。

代码示例

Swift 版本

// 注意添加版本判断,该组件仅支持iOS 14+
if #available(iOS 14.0, *) {
    let colorPicker = UIColorPickerViewController()
    // 仅保留网格色卡标签
    colorPicker.supportedColorPickers = [.grid]
    // 其他常规配置,比如设置默认选中色、代理
    colorPicker.selectedColor = .white
    colorPicker.delegate = self
    present(colorPicker, animated: true)
} else {
    // 低版本系统兼容逻辑
}

Objective-C 版本

// 注意添加版本判断,该组件仅支持iOS 14+
if (@available(iOS 14.0, *)) {
    UIColorPickerViewController *colorPicker = [[UIColorPickerViewController alloc] init];
    // 仅保留网格色卡标签
    colorPicker.supportedColorPickers = @[UIColorPickerViewControllerPickerGrid];
    // 其他常规配置,比如设置默认选中色、代理
    colorPicker.selectedColor = [UIColor whiteColor];
    colorPicker.delegate = self;
    [self presentViewController:colorPicker animated:YES completion:nil];
} else {
    // 低版本系统兼容逻辑
}
注意事项
  • 不要尝试通过遍历子视图、修改隐藏属性的方式隐藏标签栏,该类操作属于非合规实现,容易在系统版本迭代后失效,也可能导致App Store审核被拒。
  • 其余标签对应的枚举值分别为光谱.spectrum、滑块.sliders、自定义调色板.palettes,如果后续有需要展示其他标签的需求,直接在数组中添加对应枚举值即可。

内容的提问来源于stack exchange,提问作者Dev Loots

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 06:36:03