gpt4 book ai didi

ios - 更改 UIToolbar 项目导致工具栏变为空白

转载 作者:搜寻专家 更新时间:2023-10-31 22:50:49 26 4
gpt4 key购买 nike

我在 Storyboard 中创建了一个自定义 UIToolbar,其中包含快退、暂停和快进 UIBarButtonItems。单击时,我试图用播放按钮替换暂停按钮。我的代码如下:

@IBOutlet weak var bottomToolbar: UIToolbar!

@IBAction func playPause() {
var newButton: UIBarButtonItem
if !self.timer.valid {
let aSelector : Selector = "updateTime"
self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: aSelector, userInfo: nil, repeats: true)
newButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Pause, target: self, action: "playPause")
}
else {
self.timer.invalidate()
newButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: self, action: "playPause")
}
var items = self.bottomToolbar.items
items?[3] = newButton
self.bottomToolbar.setItems(items, animated: true)
}

工具栏初始化为带有白色按钮的深灰色背景。然而,在尝试按钮切换之后,整个工具栏变白了。有什么想法吗?

更新 1:
因此,在弄乱颜色并多步执行代码之后,我发现除了工具栏变白之外,只有暂停/播放按钮消失了。但即使在消失之后,点击它应该在的地方仍然会向 VC 发送信号。尝试将工具栏背景重置为深灰色也无济于事。

最佳答案

我最近遇到了类似的问题。有用的是将 toolbar.Items 设置为一个空数组,然后再将其再次设置为您的项目。

我的 swift 非常有限,所以请原谅任何编译错误:

 items = self.bottomToolbar.items
self.bottomToolbar.setItems:([], animated: false)
items?[3] = newButton
self.bottomToolbar.setItems(items, animated: true)

关于ios - 更改 UIToolbar 项目导致工具栏变为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29176364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com