从 Swift 中的属性检查器列表更改栏按钮图像 [英] Change Bar Button Image from Attribute Inspector List in Swift

查看:17
本文介绍了从 Swift 中的属性检查器列表更改栏按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当按下属于工具栏的条形按钮(播放)时,我想将其图标更改为暂停图像.在 Bar Button Identifier 的 Attribute Inspector 下首次创建按钮时设置 Play 图像.

When a bar button (Play) belonging to the toolbar is pressed I want to change its icon to a Pause image. The Play image is set when button is first created under the Attribute Inspector for the Bar Button Identifier.

我也尝试更改图像的暂停图像也来自 identifier 下的下拉列表.

The pause image I am trying to change the image too is also from the drop list under identifier .

我尝试创建了一个对按钮的插座引用并调用了适当的方法,但在尝试传递 UIIMage 参数时卡住了,因为不知道如何引用在 Inspector 下拉列表下找到的暂停图像.

I have tried created a outlet reference to the button and called the appropriate method but am stuck when trying to pass the UIIMage parameter as do not know how to reference the pause image found under Inspector drop down list.

@IBOutlet weak var PauseBarButtonOulet: UIBarButtonItem!

PauseBarButtonOulet.setBackButtonBackgroundImage(UIIMage?, forState: .Normal, barMetrics: .Default);

感谢任何输入.

推荐答案

你可以这样设置按钮样式:

You can set the button style like this:

//setButton to play
self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: self, action: "TheMethodThatTheButtonShouldCall"), animated: true)
//setButton to pause
self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Pause, target: self, action: "TheMethodThatTheButtonShouldCall"), animated: true)

或者,如果暂停图标是您自己的自定义暂停图像文件,请像这样获取图像:

Or if the pause icon is your own custom pause image file, get the image like this:

使用UIImage(named:"imageFileName.png")

var image : UIImage = UIImage(named:"ImageName")

这篇关于从 Swift 中的属性检查器列表更改栏按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆