如何在代码中更改UIBarButtonItem的样式 [英] How can i change the style of UIBarButtonItem in code
问题描述
我正在使用UIBarButtonSystemItemPlay播放我的音频文件,我想在点击它时动态更改它的样式。有可能吗?如果是的话请帮助我。这是我的代码,其中_playPause是UIBarButtonSystemItemPlay的IBOutlet。提前致谢。
I am using UIBarButtonSystemItemPlay to play my audio file and i want to change it's style dynamically when i click it. Is it possible?, if yes, then please help me. This is my code, where _playPause is IBOutlet of UIBarButtonSystemItemPlay. Thanks in advance.
- (IBAction)playPause:(UIBarButtonItem *) sender
{
if (_playPause.style == UIBarButtonSystemItemPlay)
{
[_playPause setStyle:UIBarButtonSystemItemPause];
[audio play];
}
else
{
[_playPause setStyle:UIBarButtonSystemItemPlay];
[audio pause];
}
}
推荐答案
<样式属性无法检索code> UIBarButtonSystemItemPlay 或 UIBarButtonSystemItemPause
。 style的类型为 UIBarButtonItemStyle
。
UIBarButtonSystemItemPlay
or UIBarButtonSystemItemPause
cannot be retrieved by style property. style is of type UIBarButtonItemStyle
.
检查文档 here 。
我建议创建两个不同的 UIBarButtonItem
,然后交替启用或禁用(例如)它们。也可以删除当前可见按钮并添加一个具有不同 UIBarButtonSystemItem
的新按钮。
I suggest to create two different UIBarButtonItem
and then enable or disable (for example) them alternately. It is also possible to remove the current visible button and add a new one with a different UIBarButtonSystemItem
.
这篇关于如何在代码中更改UIBarButtonItem的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!