使用 xib 和 viewController
Working with xib and viewController
我在 .xib 文件中有一个按钮。
我希望如果我单击该按钮,viewController 的 .xib 文件颜色应该更改。
我该怎么做?
我应该使用 NSNotification 还是有其他方法可以做到这一点?
A UIViewController
没有颜色。您可能在谈论它的根视图,如果它嵌入在 UINavigationController
?
中,可能是 UINavigationBar
中的 tintColor
在任何情况下,连接到您的 UIButton
的 IBAction
都可以满足您的需求。
将 xib 上的 UIButton
与继承自 UIViewController
的 class 中的 IBAction
连接起来,并更改 view
属性 UIViewController
。您可以使用 self.view.backgroundColor
这是执行该操作的简单代码片段。希望对你有帮助。
@IBAction func myButtonPressed(sender: AnyObject) {
self.view.backgroundColor = UIColor.redColor() //Or any color of your choice
}
我在 .xib 文件中有一个按钮。
我希望如果我单击该按钮,viewController 的 .xib 文件颜色应该更改。
我该怎么做?
我应该使用 NSNotification 还是有其他方法可以做到这一点?
A UIViewController
没有颜色。您可能在谈论它的根视图,如果它嵌入在 UINavigationController
?
UINavigationBar
中的 tintColor
在任何情况下,连接到您的 UIButton
的 IBAction
都可以满足您的需求。
将 xib 上的 UIButton
与继承自 UIViewController
的 class 中的 IBAction
连接起来,并更改 view
属性 UIViewController
。您可以使用 self.view.backgroundColor
这是执行该操作的简单代码片段。希望对你有帮助。
@IBAction func myButtonPressed(sender: AnyObject) {
self.view.backgroundColor = UIColor.redColor() //Or any color of your choice
}