zoukankan      html  css  js  c++  java
  • Swift

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

      

  • 相关阅读:
    Android 内存溢出解决方案(OOM) 整理总结
    浅思OC的语言特性
    netsh winsock reset 11003
    Utility
    百度地图手机四角坐标
    Mysql 导入 MSSQL
    Python import 指定目录中的模块
    POJ:3061-Subsequence(尺取法模板详解)
    POJ:3616-Milking Time
    POJ:2385-Apple Catching(dp经典题)
  • 原文地址:https://www.cnblogs.com/Rinpe/p/5050808.html
Copyright © 2011-2022 走看看