设置视图的背景颜色
Setting a View's background color
我创建了自定义颜色并想将其设置为我的视图颜色。在我的视图 ViewController 中,我在 viewDidLoad 方法中放置了 self.view.backgroundColor = UIColor.jLimeColor()
。它不起作用。有什么建议么?
自定义颜色
extension UIColor
{
class func jLimeColor () -> UIColor
{
return UIColor(red: 98, green: 255, blue: 130, alpha: 1)
}
}
如果你只想在一个 ViewController 中使用这种自定义颜色,你可以只在 Class.
中编写函数
func customColor() -> UIColor {
return UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
}
如果要为 Global Hierarchy
使用这种颜色,则可以创建一个 CustomColor Class
。
import UIKit
public let CustomColor1 = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
public let CustomColor2 = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
public let CustomColor3 = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
在主 "View" 之上有一个自定义视图。当我设置颜色时,正在设置下面的主要 "View" 。我只需要为视图创建一个出口或手动设置它。谢谢!
我创建了自定义颜色并想将其设置为我的视图颜色。在我的视图 ViewController 中,我在 viewDidLoad 方法中放置了 self.view.backgroundColor = UIColor.jLimeColor()
。它不起作用。有什么建议么?
自定义颜色
extension UIColor
{
class func jLimeColor () -> UIColor
{
return UIColor(red: 98, green: 255, blue: 130, alpha: 1)
}
}
如果你只想在一个 ViewController 中使用这种自定义颜色,你可以只在 Class.
中编写函数func customColor() -> UIColor {
return UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
}
如果要为 Global Hierarchy
使用这种颜色,则可以创建一个 CustomColor Class
。
import UIKit
public let CustomColor1 = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
public let CustomColor2 = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
public let CustomColor3 = UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 1.0)
在主 "View" 之上有一个自定义视图。当我设置颜色时,正在设置下面的主要 "View" 。我只需要为视图创建一个出口或手动设置它。谢谢!