gpt4 book ai didi

ios - 在 ContainerViewController 类中以编程方式为 UIButton 设置新的背景图像,具体取决于它所在的父 View

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

    override func viewWillAppear(_ animated: Bool) {
if (self.parent?.isKind(of: GuideViewController.self))!{

relatedGuide1.setBackgroundImage(#imageLiteral(resourceName: "ab-logo-rebrand"), for: .normal)
}
}

我也尝试将其写入 viewDidLoad 中。没有雪茄。这很奇怪,因为我能够做到这一点

@IBAction func relatedGuidePressed(_ sender: Any) {
if (self.parent?.isKind(of: GuideViewController.self))!{
show(guideViewController, sender: nil)

}

}

这个顶部方法基本上显示了一个不同的 View Controller ,具体取决于它所在的父级。作为引用,我基本上有 7 个 View Controller ,它们都具有相同的布局,但显示的数据不同。所以我认为 ContainerView 将是最好的方法。一切都进展顺利,但这是最后一 block 拼图。理想情况下,我希望 js 能够做一些比按钮上的一堆条件语句更有效的事情,但这是迄今为止我想到的最好的。

结论:ContainerView 中的 UIButton。我希望 UIButton 根据它所在的 ParentView 进行更改(视觉上和功能上)。

如果有人能帮忙的话。保佑

最佳答案

嘿伙计们,我找到了答案。它与 View 层次结构以及何时调用哪个回调有关,我不会深入讨论(主要是因为我的解释可能是错误的),但您确实需要在 viewDidAppear NOT viewWillAppear 方法中实现代码。如下:

override func viewDidAppear(_ animated: Bool) {



if (self.parent?.isKind(of: IDController.self))!{

UpNextButton.backgroundColor = UIColor.init(hex: "536BA1")
nextUpButtonImage.image = #imageLiteral(resourceName: "logo")


//BUTTONS
relatedGuideButton1.backgroundColor = UIColor.init(hex: "400080") //purple
relatedGuideButton1.setImage(#imageLiteral(resourceName: "onenote-logo"), for: .normal)
relatedGuideButton1.setTitle("TAKE NOTES", for: .normal) }

如果您需要一些功能以及按钮,那就更简单了。只需使用相同的条件并像任何其他 IBAction 一样实现即可。就像这样:

 @IBAction func relatedGuideButton1Pressed(_ sender: Any) {

if (self.parent?.isKind(of: IDController.self))!{

show(notesController, sender: nil)
}

else if (self.parent?.isKind(of: DriveController.self))! ||
(self.parent?.isKind(of: ShareController.self))! ||
(self.parent?.isKind(of: NoteController.self))! ||
(self.parent?.isKind(of: AppsController.self))! ||
(self.parent?.isKind(of: SymbolsController.self))! ||
(self.parent?.isKind(of: MonthController.self))! {

show(guideViewController, sender: nil)

}

}

干杯!

关于ios - 在 ContainerViewController 类中以编程方式为 UIButton 设置新的背景图像,具体取决于它所在的父 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44930451/

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