gpt4 book ai didi

ios - 自定义UIButton时不同状态的IBInpectable属性

转载 作者:行者123 更新时间:2023-11-30 12:49:50 25 4
gpt4 key购买 nike

我已经自定义了 UI 按钮并使用 IBInspectable 创建了一些属性。但是,我还需要选定或突出显示状态的相同属性,并且可以在 Interface Builder 中进行检查。我想知道是否可以实现?

这是我创建的自定义按钮

    @IBDesignable
class ImageLabelButton: UIButton{
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
let buttonImgView = UIImageView()
let buttonLabel = UILabel()
// let stackView = UIStackView()



// Override property observors
@IBInspectable
var textColor:UIColor? {
get {
return buttonLabel.textColor
}
set(newValue) {
self.buttonLabel.textColor = newValue
}
}
}

我也想为其他状态创建一个 IBInspectable 属性。能做到吗?谢谢!

最佳答案

简短的回答?不可以。Interface Builder 无法“处理”代码。

  • 我需要知道我的应用何时处于纵向或横向(各种 slider 控件位于底部或右侧,具体取决于此)。

我可以为此使用 IB 吗?如果我需要知道 iPad 上的情况,则不需要……除非有滑出或分屏功能,否则它的尺寸等级是 (wR hR)。我可以为每个方向“设计”一些东西,但即使是 Apple - WWDC'16,使应用程序自适应,第 2 部分 - 最终也将代码放入 viewWillLayoutSubviews() 中。

  • 在 Storyboard上放置一个 UIButton。你能加工水龙头吗?将 UISlider 放在 Storyboard 上。你能向左或向右平移吗?

您正在要求设计时工具处理运行时操作。

再说一遍,您无法将某些按钮状态设置为 IBDesignable。

关于ios - 自定义UIButton时不同状态的IBInpectable属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41135365/

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