码迷,mamicode.com
首页 > 编程语言 > 详细

swift 初见-6集合类型与Cocoa Touch混编

时间:2014-11-01 09:43:28      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   for   sp   div   on   log   

// 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

 

swift 初见-6集合类型与Cocoa Touch混编

标签:style   blog   color   ar   for   sp   div   on   log   

原文地址:http://www.cnblogs.com/lovelifeloveme/p/4066382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!