简体   繁体   English

在Interface Builder中设置UITabBarItem图像/图标

[英]Set UITabBarItem image/icon in Interface Builder

I am creating a custom view in Interface Builder. 我在Interface Builder中创建自定义视图。 The view has a UITabBar at the bottom. 该视图的底部有一个UITabBar I want to set the icon of each "button" to one of the system provided icons that are in Apple's UITabBarItem Class Reference . 我想将每个“按钮”的图标设置为Apple的UITabBarItem类参考中系统提供的图标之一。

I tried to do this by typing in 'UITabBarSystemItemRecents' in the 'Image' field found at Inspector -> Attributes inspector -> Bar Item -> Image . 我试图通过在Inspector-> Attributes inspector-> Bar Item-> Image中找到的'Image'字段中键入'UITabBarSystemItemRecents'来做到这一点。 Before this, I first selected the UITabBar and then the UITabBarItem I wanted the image for. 在此之前,我首先选择了UITabBar ,然后选择了我想要图像的UITabBarItem

This did not work however, I just get a square instead. 但是,这没有用,我只是得到一个正方形。 I did some searching and found that you can set the icon programmatically, but I want to do as much as possible of the view in Interface Builder. 我进行了一些搜索,发现可以以编程方式设置图标,但是我想在Interface Builder中尽可能多地处理视图。

I use Xcode 5.0.2 and develop for iOS 7. 我使用Xcode 5.0.2并为iOS 7开发。

You can easily set it in Attributes inspector on right panel..Set image as shown below 您可以在右侧面板的“属性”检查器中轻松设置它。设置图像如下图所示

在此处输入图片说明

If you drag and drop images in you file.access it from media library: 如果将图像拖放到文件中,请从媒体库访问它:

在此处输入图片说明

Note: The full credit should go to null and akash . 注意:完整信用应为nullakash They contributed by answering half of the question each. 他们贡献了每个问题的一半。

You can't have one of the icons from Apple that are avaible directly in Interface Builder and have a custom title. 您不能从Apple中直接在Interface Builder中获得并且具有自定义标题的图标之一。 Instead, you must download the icon you want to use (Apple-looking icons are avaible at icons8 ), add it to the project resources and then pick it from the dropdown menu at Inspector -> Attributes inspector -> Bar Item -> Image . 取而代之的是,您必须下载要使用的图标(在icon8上可以看到Apple的图标),将其添加到项目资源中,然后从Inspector-> Attributes inspector-> Bar Item- > Image的下拉菜单中进行选择。

If you want to use Apple's Recent image then you need to select it from inspector -> Tab Bar Item -> Identifier. 如果要使用Apple的“最近”图像,则需要从检查器->“选项卡栏项”->“标识符”中选择它。

Alternatively you can add the image you want to your app and pick it from inspector -> Bar Item -> Image. 或者你可以选择你想要的图像添加到您的应用程序,并从督察捡起来- >栏项目- >图像。

Note that if you choose the identifier you cannot set the title and vise versa. 请注意,如果选择标识符,则不能设置标题,反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当在 Xcode 11, beta 2 的 Interface Builder 中指定条形着色颜色时,UITabBarItem 图标的颜色对于 iOS 13 不正确 - UITabBarItem icon not colored correctly for iOS 13 when a bar tint color is specified in Interface Builder in Xcode 11, beta 2 如何在UITabbaritem上设置图像? - How to set image on UITabbaritem? 如何在uitabbaritem中默认设置图像 - How to set image in uitabbaritem for default 以编程方式为每个链接的 ViewController 设置 UITabBarItem 图标 - Programmatically set the UITabBarItem icon for every linked ViewController 界面构建器中是否可以为常规UIView设置图像? - is there an option in interface builder to set an image for a regular UIView? 在界面构建器/故事板中设置UIButton图像 - Set UIButton image in interface builder / storyboard 通过代码设置在Interface Builder中创建的UIButton的图像 - Set Image of UIButton Created in Interface Builder, by code 如何使用字形图标代替UITabBarItem图像? - How to use a glyph icon in place of a UITabBarItem image? Swift:使用FontAwesome图标作为UITabBarItem图像 - Swift: Use a FontAwesome icon as a UITabBarItem image 尝试设置selectedImage时,UITabBarItem没有可见的界面 - No visible interface for UITabBarItem when trying to set selectedImage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM