【问题标题】:How to use default iOS images?如何使用默认的 iOS 图像?
【发布时间】:2026-01-24 01:15:02
【问题描述】:

我知道如何在 iOS 应用程序中使用图像。但我不知道如何使用开发者网站中提到的默认图像,例如共享或书签图标。

我想使用它们。我需要下载这些图像集还是 Xcode 中提供的图像集?

如果我们必须下载它们,我可以从哪里获得这些图标?

【问题讨论】:

标签: ios7 icons


【解决方案1】:

现在从 Swift 5.1 和 Xcode 11 开始,您可以使用基于矢量的新 UIImage Api UIImage(systemName: "imageName") 从 1500 多个系统图像中加载 1 个,因此无需担心不同尺寸的质量

https://developer.apple.com/design/resources/

【讨论】:

  • 谢谢,系统图像是 systemName:String,我的资产图像是 name:String
  • 但仅适用于 iOS 13.0 及更高版本。知道如何在 iOS 11 或 12 上使用它吗?
【解决方案2】:

Swift 5.1,Xcode 11

这是 SF Symbols 的一个示例。苹果提供了大约 1500 个系统图像,具有不同的权重和比例。

let homeSymbolConfiguration = UIImage.SymbolConfiguration(pointSize: 55, weight: .black)
let homeImage = UIImage(systemName: "house", withConfiguration: homeSymbolConfiguration)
let width = homeImage?.size.width
let height = homeImage?.size.height
let homeButton = UIButton(frame: CGRect(x: 100, y: 100, width: width!, height: height!))
homeButton.tintColor = UIColor.gray
homeButton.setImage(homeImage, for: .normal)
view.addSubview(homeButton)

Apple 为 Mac 应用程序 SF Symbols 提供了所有系统映像。它们都是 svg 格式,意味着它们是可扩展的。您可以导出和编辑它们。

关注此 WWDC 2019 会议 206。 https://developer.apple.com/videos/play/wwdc2019/206/

【讨论】:

  • 需要 iOS 13 或更高版本。
  • 不幸的是,您不能像在 iOS 13 及更高版本上那样直接在 iOS 12 及更低版本上使用 SF Symbols。如果您想在 iOS 12 及更低版本上使用任何符号,您需要从 SF Symbols Mac 应用程序中导出它们,并将它们作为常规资产导入您的资产目录中。
【解决方案3】:

开发人员无法直接访问这些图像。我的意思是你不能像这样初始化图像对象:

UIImage *image = [UIImage imageNamed:@"name_of_system_image"];

但是您可以使用系统类型显示一些图像。例如,您可以使用提供标准图标的系统类型来初始化 UIBarButtonItem
- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action

UIBarButtonSystemItem 提供了这样的类型:

UIBarButtonSystemItemDone, UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItem书签,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItem撤消,
UIBarButtonSystemItemRedo,
UIBarButtonSystemItemPageCurl

【讨论】:

  • 不幸的是,在这种情况下,您无法修改标题并坚持使用 iOS 默认标题,对吗?
  • 是的,@YuriS,您不能更改系统项目的标题。这是因为它们会自动为您“本地化”:它们将以用户在其设备上设置的任何语言显示。如果您想使用自己的文本作为标题,并且希望以不同的语言显示文本,则必须为您的文本提供自己的翻译。
【解决方案4】:

对于 swift 中使用的 Systme 图像,只需这样做

imageView?.image = UIImage(systemName: "face.smiling")

编码愉快 :)

系统资源在这里:https://developer.apple.com/design/resources/

【讨论】:

    【解决方案5】:

    对于旧 iOS 版本:

     if #available(iOS 13.0, *) {
                cell.buttonImageIcon.image = UIImage(systemName: "info.circle.fill")
                cell.profileButton.tintColor = UIColor.white
                cell.profileButton.setTitle("PERSONAL INFORMATION", for: .normal)
            } else {
                // Fallback on earlier versions
            }
    

    【讨论】: