swift 初见-6集合类型与Cocoa Touch混编
// Playground - noun: a place where people can play import UIKit var str = "Hello, playground" // color与=号之间必须有个空格 let colors = [ "Air Force Blue":(red:93,green:138,blue:168), "Bittersweet":(red:254,green:111,blue:94), "Canary Yellow":(red:255,green:239,blue:0), "Dark Orange":(red:255,green:140,blue:0) ] var backView = UIView(frame: CGRectMake(0, 0,320.0,CGFloat(colors.count*50))) backView.backgroundColor=UIColor.blackColor() var index=0 for (colorName,rgbTuple) in colors { var colorStripe=UILabel(frame: CGRectMake(0.0,CGFloat(index*50+5), 320, 40)) colorStripe.backgroundColor=UIColor( red:CGFloat(rgbTuple.red), green:CGFloat(rgbTuple.green) , blue:CGFloat(rgbTuple.blue), alpha: 1.0 ) colorStripe var colorNameLabel=UILabel(frame: CGRectMake(0.0, 0.0,300, 40)) colorNameLabel.font=UIFont(name:"Arial", size: 24.0) colorNameLabel.textColor=UIColor.blackColor() colorNameLabel.text=colorName colorStripe.addSubview(colorNameLabel) backView.addSubview(colorStripe) index++ } backView var newbBackView=UIView(frame: CGRectMake(0,CGFloat(colors.count*5),320, CGFloat(colors.count*50))) newbBackView.backgroundColor=UIColor.orangeColor() index=0 for(colorName,rgbTuple) in colors { var colorStripe=UILabel(frame: CGRectMake(0,CGFloat(index*50+5), 320, 40)) colorStripe.backgroundColor=UIColor(red: CGFloat(rgbTuple.red), green: CGFloat(rgbTuple.green), blue: CGFloat(rgbTuple.blue), alpha: 0.5) colorStripe.text=colorName colorStripe.textAlignment=NSTextAlignment.Center index++ newbBackView.addSubview(colorStripe) } newbBackView
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。