【发布时间】:2018-03-09 19:50:14
【问题描述】:
我必须在 UIButton 上切换两个图像(带有动画),但这会将我的标签隐藏在 UIButton 上的图像后面。因此,我在其中添加了 UILabel 的子视图,但也没有显示。我什至尝试将子视图放在前面,但这也不起作用。
let options = [option_1, option_2, option_6]
var imageArray = [UIImage]()
imageArray.append( UIImage(named: "light_button.png" )! )
imageArray.append( UIImage(named: "dark_button.png" )! )
let label = UILabel(frame: CGRect(x: 0, y: 0, width: self.option_1.frame.width, height: self.option_1.frame.width))
label.text = "HEY"
label.font = UIFont.systemFont(ofSize: 18)
option_1.addSubview(label)
option_1.bringSubview(toFront: label)
for option in options{
option?.setImage( UIImage(named: "green_button.png")!, for: .normal)
option?.imageView!.animationImages = imageArray
option?.imageView!.animationImages = imageArray
option?.setTitle("TEST TEXT", for: .normal) //Even this don't work
option?.imageView!.animationDuration = 2.35
option?.imageView!.startAnimating()
}
怎么了?
【问题讨论】:
-
你在选项数组中添加了什么?
-
@ishika 这些是 UIButtons。
-
我的意思是问您是否以编程方式创建了插座或按钮?
-
@ishika 我创建了带有插座的 UIButton。并且有6个这样的按钮。我想在按钮上切换图像以突出显示和取消突出显示 3 个按钮。哪些被添加到数组中(选项)
-
你真的不需要管理所有这些数组和所有......你可以通过故事板管理所有这些状态,只需要根据需要更改其状态。其余的一切都将按照状态配置中的设置显示。
标签: ios swift swift3 uibutton uilabel