微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CGColor 数组的问题

如何解决CGColor 数组的问题

从我的 CGColor 数组中的一个项目设置我的 UIView .backgroundColor 会导致构建错误
“表达类型不明确,没有更多上下文”
(在代码底部

我想显示 UIView 矩形并控制每个矩形的颜色。

这是代码 - 在底部构建错误..

class ViewController: UIViewController 
{
// the array of UIView's,one for each rectangle:  
            static var map_sectors_UIView: [UIView] = [] 

 override func viewDidLoad()    
 {
// init the UIView array:
                for map_sector_index in 0...App.total_map_sectors-1
                {
                    let new_UIView = UIView()
                    new_UIView.translatesAutoresizingMaskIntoConstraints = false //You need to call this property so the image is added to your view
                    ViewController.map_sectors_UIView[ map_sector_index ] = new_UIView 
                }

            super.viewDidLoad()

// Add the subviews:
            for map_sector_index in 0...App.total_map_sectors-1
            {
                view.addSubview( ViewController.map_sectors_UIView[ map_sector_index ] )
            }
. . .
// init each UIView rectangle:
                    ViewController.map_sectors_UIView[ map_sector_index ].frame = CGRect(    x: map_sector_column * App.sector_width_pix,y: map_sector_row * App.sector_height_pix,width: App.sector_width_pix,height: App.sector_height_pix )
ViewController.map_sectors_UIView[ map_sector_index ].backgroundColor = .green

. . .


 class App
 {
            static var sector_colors_array: [CGColor] = []
. . .
    static func init_class()
    {

// Declare array of colors for the UIView rectangles:
        sector_colors_array = [CGColor]( repeating: UIColor.black.cgColor,count: total_map_sectors )
}

. . .

// display all the rectangles:
        dispatchQueue.main.sync
        {    
                ViewController.map_sectors_UIView[ sector_index ].backgroundColor = sector_colors_array[ sector_index ]

.......... gets build error: "Type of expression is ambiguous without more context"

解决方法

谢谢,马特。易于修复。刚刚用 UIColor 替换了对 CGColor 的引用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。