【发布时间】:2026-01-24 01:15:02
【问题描述】:
我知道如何在 iOS 应用程序中使用图像。但我不知道如何使用开发者网站中提到的默认图像,例如共享或书签图标。
我想使用它们。我需要下载这些图像集还是 Xcode 中提供的图像集?
如果我们必须下载它们,我可以从哪里获得这些图标?
【问题讨论】:
-
您能否提供显示您要求的图像的页面的链接?
-
或者如果你附上问题会更好。
我知道如何在 iOS 应用程序中使用图像。但我不知道如何使用开发者网站中提到的默认图像,例如共享或书签图标。
我想使用它们。我需要下载这些图像集还是 Xcode 中提供的图像集?
如果我们必须下载它们,我可以从哪里获得这些图标?
【问题讨论】:
现在从 Swift 5.1 和 Xcode 11 开始,您可以使用基于矢量的新 UIImage Api UIImage(systemName: "imageName") 从 1500 多个系统图像中加载 1 个,因此无需担心不同尺寸的质量
【讨论】:
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/
【讨论】:
开发人员无法直接访问这些图像。我的意思是你不能像这样初始化图像对象:
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
【讨论】:
对于 swift 中使用的 Systme 图像,只需这样做
imageView?.image = UIImage(systemName: "face.smiling")
编码愉快 :)
【讨论】:
对于旧 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
}
【讨论】: