问答详情
源自:5-7 字典实战和UIKit初探

代码报错的进,希望能帮到你

import UIKit


let colors =

[

    "A":(red:93,green:138,blue:168),

    "B":(red:254,green:111,blue:94),

    "C":(red:255,green:239,blue:0),

    "D":(red:255,green:140,blue:0),

    "E":(red:143,green:0,blue:255),

    "F":(red:113,green:188,blue:120),

    "G":(red:228,green:155,blue:15),

    "H":(red:244,green:0,blue:161),

    "I":(red:252,green:247,blue:94),

    "J":(red:165,green:11,blue:94)

]

var backView=UIView(frame:CGRect(x: 0.0, y: 0.0, width: 320.0, height: Double(colors.count * 50)))

backView.backgroundColor=UIColor.black

backView

var index=0

for (colorName,rgbTuble) in colors

{

    var colorStripe=UILabel(frame:CGRect(x: 0.0, y: Double(index*50+5), width: 320.0, height: 40.0))

    colorStripe.backgroundColor =

        UIColor(

            red: CGFloat(rgbTuble.red)/255.0,

            green: CGFloat(rgbTuble.green)/255.0,

            blue: CGFloat(rgbTuble.blue)/255.0,

            alpha: 1.0

    )

    var colorNameLabel=UILabel(frame: CGRect(x: 0.0, y: 0.0, width: 300.0, height: 40.0))

    colorNameLabel.font = UIFont(name:"Arial", size: 24.0)

    colorNameLabel.textColor = UIColor.black

    colorNameLabel.textAlignment = NSTextAlignment.right

    colorNameLabel.text = colorName

    colorStripe.addSubview(colorNameLabel)

    backView.addSubview(colorStripe)

    index+=1

}

backView


UIColor.black 现在是一个属性值,不是方法

CGRectMake() - > CGRect()


https://img4.mukewang.com/5b74f7700001151703440519.jpg


提问者:慕雪9091725 2018-08-16 12:04

个回答