[英]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 . 注意:完整信用应为null和akash 。 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.