//: Playground - noun: a place where people can play

import UIKit

// 数据源
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),
"Electric Violet":(red:255, green:140, blue:0),
"Fern":(red:113, green:188, blue:120),
"Gamboge":(red:228, green:155, blue:15),
"Hollywood Cerise":(red:244, green:0, blue:161),
"Icterine":(red:252, green:247, blue:94),
"Jazzberry Jam":(red:165, green:11, blue:94),
] // 创建一个UIView用于显示
var rect = CGRectMake(0, 0, 320, (CGFloat)(colors.count * 50));
var backView = UIView(frame:rect)
backView.backgroundColor = UIColor.blackColor()
backView var index = 0
for (colorName, rgbTuple) in colors
{
  // 创建UILabel用来显示颜色, 并将其放在view上
var labelRect = CGRectMake(0, (CGFloat)(index * 50 + 5), 320, 40)
var colorStripe = UILabel(frame: labelRect)
colorStripe.text = colorName
colorStripe.backgroundColor =
UIColor(
red: (CGFloat)(rgbTuple.red) / 255.0,
green: (CGFloat)(rgbTuple.green) / 255.0,
blue: (CGFloat)(rgbTuple.blue) / 255.0,
alpha: 1.0
)
colorStripe
backView.addSubview(colorStripe)
index++
}
backView

  

Swift - 21 - 字典实战和UIKit初探的更多相关文章

  1. 【SpringBoot】SpringBoot拦截器实战和 Servlet3.0自定义Filter、Listener

    =================6.SpringBoot拦截器实战和 Servlet3.0自定义Filter.Listener ============ 1.深入SpringBoot2.x过滤器Fi ...

  2. Swift - 从字典(或者Alamofire)直接创建Model文件的工具

    Swift - 从字典(或者Alamofire)直接创建Model文件的工具 效果 1. 常规生成model的方式 2. 通过debug创建model的方式 特性 1. 可以处理JSON格式的字典数据 ...

  3. Swift - 19 - 字典的初始化

    //: Playground - noun: a place where people can play import UIKit // 注意: swift中的字典用的也是中括号, 和OC的大括号是不 ...

  4. Swift json字典转模型 项目记录

    背景 最近项目开始转用Swift3开发,由于Swift中json(字典)转模型的选择方案较多,笔者最开始选择了HandyJSON的方案,在使用一段时间后发现当要进行某个字段取值使用时需要进行各种的转化 ...

  5. iOS开发零基础--Swift教程 字典

    字典的介绍 字典允许按照某个键来访问元素 字典是由两部分集合构成的,一个是键(key)集合,一个是值(value)集合 键集合是不能有重复元素的,而值集合是可以重复的,键和值是成对出现的 Swift中 ...

  6. 3. Swift 数组|字典|集合

    在OC中数组,字典,集合有自己的表示方法,分别是Array,Dictionary,Set 与 String 都属于数值类型变量,他们都属于结构体. 使用简介灵活多变,个人感觉可读性变差了很多,用起来由 ...

  7. swift Dictionary 字典

    // //  main.swift //  字典 // //  Created by zhangbiao on 14-6-15. //  Copyright (c) 2014年 理想. All rig ...

  8. Swift - 使用UI Dynamics给UIKit组件添加移动吸附行为

    UI Dynamics是UIKit的一个新组成部分,它向iOS中的视图提供了与物理学有关的功能和动画.可以让你向视图中引入力和物理属性,可以让你的视图弹跳,舞动,受重力影响等等. 下面通过样例,演示使 ...

  9. Swift - 使用UI Dynamics给UIKit组件添加重力和碰撞行为

    UI Dynamics是UIKit的一个新组成部分,它向iOS中的视图提供了与物理学有关的功能和动画.可以让你向视图中引入力和物理属性,可以让你的视图弹跳,舞动,受重力影响等等. 下面通过样例,演示使 ...

随机推荐

  1. Unity NGUI 网络斗地主 -制作图集 Atlas

    Unity NGUI 网络斗地主 -制作图集 Atlas by @杨海龙 开发环境   Win7+Unity4.2.1f4+NGUI 3.0.4版本 这一节告诉大家如何制作(图集)Atlas! 1.首 ...

  2. python operator模块

    官网:https://docs.python.org/3.4/library/operator.html http://pymotw.com/2/operator/

  3. Unity 用C#脚本读取JSON文件数据

    读取JSON文件数据网上有很多方法吗,这里采用SimpleJSON,关于SimpleJSON的介绍参考以下链接:http://wiki.unity3d.com/index.php/SimpleJSON ...

  4. BZOJ 1083 [SCOI2005]繁忙的都市

    1083: [SCOI2005]繁忙的都市 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1664  Solved: 1080[Submit][Sta ...

  5. 【转】寻找最好的笔记软件:三强篇(EverNote、Mybase、Surfulater) (v1.0) (

    原文网址:http://blog.sina.com.cn/s/blog_46dac66f01000b57.html 寻找最好的笔记软件:三强篇(EverNote.Mybase.Surfulater) ...

  6. Merge Intervals——LeetCode

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  7. UVAlive2531 The K-League(最大流)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33451 [思路] 最大流. 大体思路是枚举每个队伍,最大流判断是否 ...

  8. 常考的算法及Java知识总结

    算法 1 字符串模式匹配问题 2 排列组合问题 3 查找排序问题 数据结构 B树(B,B*,B+,红黑树)和二叉树的区别,MAP,hashmap, JAVA: 线程sleep,wait,wake(), ...

  9. apt局域网源搭建

    1, 准备Packages.gz

  10. MongoDB 逻辑与操作

    看下面两个例子 rs1:PRIMARY> db.display.find({$and: [{$where: '(1386813645 - this.last_active_time > 3 ...