【iOS】Web Color 的 Swift 实现

用Swift语言重写Web Color这个类。

这次是用函数实现的,感觉也非常简洁。眼下(2014.6.28) Xcode 6的方法提示还不健全,就仅仅实现了用颜色名字创建颜色的功能。

最新代码&相关资料下载地址:https://github.com/duzixi/WebColors-with-Swift (持续维护)

使用方法说明:

WebColor.swift文件导入project,然后直接就能够使用:

self.view.backgroundColor =webColor("天蓝色");

以下上代码:

//
//  WebColor.swift
//
//  Created by 杜子兮 on 14-6-28.
//  Copyright (c) 2014年 lanou. All rights reserved.
//

import UIKit

func webColor(value: String) -> UIColor {

    switch value {
        case "lightPink", "浅粉红":
            return UIColor(red: 255/255.0, green: 182/255.0, blue: 193/255.0, alpha: 1.0)
        case "pink", "粉红":
            return UIColor(red: 255/255.0, green: 192/255.0, blue:  203/255.0, alpha: 1.0)
        case "crimson", "猩红":
            return UIColor(red: 220/255.0, green: 20/255.0, blue:  60/255.0, alpha: 1.0)
        case "lavenderBlush", "脸红的淡紫色":
            return UIColor(red: 255/255.0, green: 240/255.0, blue:  245/255.0, alpha: 1.0)
        case "paleVoiletRed", "苍白的紫罗兰红色":
            return UIColor(red: 219/255.0, green: 112/255.0, blue:  147/255.0, alpha: 1.0)
        case "hotPink", "热情的粉红":
            return UIColor(red: 255/255.0, green: 105/255.0, blue:  180/255.0, alpha: 1.0)
        case "deepPink", "深粉红":
            return UIColor(red: 255/255.0, green: 20/255.0, blue:  147/255.0, alpha: 1.0)
        case "mediumVoiletRed", "适中的紫罗兰红色":
            return UIColor(red: 199/255.0, green: 21/255.0, blue:  133/255.0, alpha: 1.0)
        case "orchid", "兰花的紫色":
            return UIColor(red: 218/255.0, green: 112/255.0, blue:  214/255.0, alpha: 1.0)
        case "thistle", "蓟":
            return UIColor(red: 216/255.0, green: 191/255.0, blue:  216/255.0, alpha: 1.0)
        case "plum", "李子":
            return UIColor(red: 221/255.0, green: 160/255.0, blue:  221/255.0, alpha: 1.0)
        case "violet", "紫罗兰":
            return UIColor(red: 238/255.0, green: 130/255.0, blue:  238/255.0, alpha: 1.0)
        case "magenta", "洋红":
            return UIColor(red: 255/255.0, green: 0/255.0, blue:  255/255.0, alpha: 1.0)
        case "fuchsia", "紫红色","灯笼海棠":
            return UIColor(red: 255/255.0, green: 0/255.0, blue:  225/255.0, alpha: 1.0)
        case "darkMagenta", "深洋红色":
            return UIColor(red: 139/255.0, green: 0/255.0, blue:  139/255.0, alpha: 1.0)
        case "purple", "紫色":
            return UIColor(red: 128/255.0, green: 0/255.0, blue:  128/255.0, alpha: 1.0)
        case "mediumOrchid", "适中的兰花紫":
            return UIColor(red: 186/255.0, green: 85/255.0, blue:  211/255.0, alpha: 1.0)
        case "darkViolet", "深紫罗兰色":
            return UIColor(red: 148/255.0, green: 0/255.0, blue:  211/255.0, alpha: 1.0)
        case "darkOrchid", "深兰花紫":
        return UIColor(red: 153/255.0, green: 50/255.0, blue:  204/255.0, alpha: 1.0)
        case "indigo", "靛青":
            return UIColor(red: 75/255.0, green: 0/255.0, blue:  130/255.0, alpha: 1.0)
        case "blueViolet", "紫罗兰的蓝色":
            return UIColor(red: 138/255.0, green: 43/255.0, blue:  226/255.0, alpha: 1.0)
        case "mediumPurple", "适中的紫色":
            return UIColor(red: 147/255.0, green: 112/255.0, blue:  219/255.0, alpha: 1.0)
        case "mediumSlateBlue", "适中的板岩暗蓝灰色":
            return UIColor(red: 123/255.0, green: 104/255.0, blue:  238/255.0, alpha: 1.0)
        case "slateBlue", "板岩暗蓝灰色":
            return UIColor(red: 106/255.0, green: 90/255.0, blue:  205/255.0, alpha: 1.0)
        case "darkSlateBlue", "深板岩暗蓝灰色":
            return UIColor(red: 72/255.0, green: 61/255.0, blue:  139/255.0, alpha: 1.0)
        case "lavender", "薰衣草花的淡紫色":
            return UIColor(red: 230/255.0, green: 230/255.0, blue:  250/255.0, alpha: 1.0)
        case "ghostWhite", "幽灵的白色":
            return UIColor(red: 248/255.0, green: 248/255.0, blue:  255/255.0, alpha: 1.0)
        case "blue", "纯蓝":
            return UIColor(red: 0/255.0, green: 0/255.0, blue:  255/255.0, alpha: 1.0)
        case "mediumBlue", "适中的蓝色":
            return UIColor(red: 0/255.0, green: 0/255.0, blue:  205/255.0, alpha: 1.0)
        case "midnightBlue", "午夜的蓝色":
            return UIColor(red: 25/255.0, green: 25/255.0, blue:  112/255.0, alpha: 1.0)
        case "darkBlue", "深蓝色":
            return UIColor(red: 0/255.0, green: 0/255.0, blue:  139/255.0, alpha: 1.0)
        case "navy", "海军蓝":
            return UIColor(red: 0/255.0, green: 0/255.0, blue:  128/255.0, alpha: 1.0)
        case "royalBlue", "皇家蓝":
            return UIColor(red: 65/255.0, green: 105/255.0, blue:  225/255.0, alpha: 1.0)
        case "cornflowerBlue", "矢车菊的蓝色":
            return UIColor(red: 100/255.0, green: 149/255.0, blue:  237/255.0, alpha: 1.0)
        case "lightSteelBlue", "淡钢蓝":
            return UIColor(red: 176/255.0, green: 196/255.0, blue:  222/255.0, alpha: 1.0)
        case "lightSlateGray", "浅石板灰":
            return UIColor(red: 119/255.0, green: 136/255.0, blue:  153/255.0, alpha: 1.0)
        case "slateGray", "石板灰":
            return UIColor(red: 112/255.0, green: 128/255.0, blue:  144/255.0, alpha: 1.0)
        case "dodgerBlue", "道奇蓝":
            return UIColor(red: 30/255.0, green: 144/255.0, blue:  255/255.0, alpha: 1.0)
        case "aliceBlue", "爱丽丝蓝":
            return UIColor(red: 240/255.0, green: 248/255.0, blue:  255/255.0, alpha: 1.0)
        case "steelBlue", "钢蓝":
            return UIColor(red: 70/255.0, green: 130/255.0, blue:  180/255.0, alpha: 1.0)
        case "lightSkyBlue", "淡天蓝色":
            return UIColor(red: 135/255.0, green: 206/255.0, blue:  250/255.0, alpha: 1.0)
        case "skyBlue", "天蓝色":
            return UIColor(red: 135/255.0, green: 206/255.0, blue:  235/255.0, alpha: 1.0)
        case "deepSkyBlue", "深天蓝":
            return UIColor(red: 0/255.0, green: 191/255.0, blue:  255/255.0, alpha: 1.0)
        case "lightBlue", "淡蓝":
            return UIColor(red: 173/255.0, green: 216/255.0, blue:  230/255.0, alpha: 1.0)
        case "powderBlue", "火药蓝":
            return UIColor(red: 176/255.0, green: 224/255.0, blue:  230/255.0, alpha: 1.0)
        case "cadetBlue", "军校蓝":
            return UIColor(red: 95/255.0, green: 158/255.0, blue:  160/255.0, alpha: 1.0)
        case "azure", "蔚蓝色":
            return UIColor(red: 240/255.0, green: 255/255.0, blue:  255/255.0, alpha: 1.0)
        case "lightCyan", "淡青色":
            return UIColor(red: 224/255.0, green: 255/255.0, blue:  255/255.0, alpha: 1.0)
        case "paleTurquoise", "苍白的绿宝石":
            return UIColor(red: 175/255.0, green: 238/255.0, blue:  238/255.0, alpha: 1.0)
        case "cyan", "青色":
            return UIColor(red: 0/255.0, green: 255/255.0, blue:  255/255.0, alpha: 1.0)
        case "aqua", "水绿色":
            return UIColor(red: 0/255.0, green: 255/255.0, blue:  225/255.0, alpha: 1.0)
        case "darkTurquoise", "深绿宝石":
            return UIColor(red: 0/255.0, green: 206/255.0, blue:  209/255.0, alpha: 1.0)
        case "darkSlateGray", "深石板灰":
            return UIColor(red: 47/255.0, green: 79/255.0, blue:  79/255.0, alpha: 1.0)
        case "darkCyan", "深青色":
            return UIColor(red: 0/255.0, green: 139/255.0, blue:  139/255.0, alpha: 1.0)
        case "teal", "水鸭色":
            return UIColor(red: 0/255.0, green: 128/255.0, blue:  128/255.0, alpha: 1.0)
        case "mediumTurquoise", "适中的绿宝石":
            return UIColor(red: 72/255.0, green: 209/255.0, blue:  204/255.0, alpha: 1.0)
        case "lightSeaGreen", "浅海洋绿":
            return UIColor(red: 32/255.0, green: 178/255.0, blue:  170/255.0, alpha: 1.0)
        case "turquoise", "绿宝石":
            return UIColor(red: 64/255.0, green: 224/255.0, blue:  208/255.0, alpha: 1.0)
        case "aquamarine", "碧绿色","绿玉":
            return UIColor(red: 127/255.0, green: 255/255.0, blue:  212/255.0, alpha: 1.0)
        case "mediumAquamarine", "适中的碧绿色":
            return UIColor(red: 102/255.0, green: 205/255.0, blue:  170/255.0, alpha: 1.0)
        case "mediumSpringGreen", "适中的春天的绿色":
            return UIColor(red: 0/255.0, green: 250/255.0, blue:  154/255.0, alpha: 1.0)
        case "mintCream", "薄荷奶油":
            return UIColor(red: 245/255.0, green: 255/255.0, blue:  250/255.0, alpha: 1.0)
        case "springGreen", "春天的绿色":
            return UIColor(red: 0/255.0, green: 255/255.0, blue:  127/255.0, alpha: 1.0)
        case "mediumSeaGreen", "适中的海洋绿":
            return UIColor(red: 60/255.0, green: 179/255.0, blue:  113/255.0, alpha: 1.0)
        case "seaGreen", "海洋绿":
            return UIColor(red: 46/255.0, green: 139/255.0, blue:  87/255.0, alpha: 1.0)
        case "honeydew", "蜂蜜":
            return UIColor(red: 240/255.0, green: 255/255.0, blue:  240/255.0, alpha: 1.0)
        case "lightGreen", "浅绿色":
            return UIColor(red: 144/255.0, green: 238/255.0, blue:  144/255.0, alpha: 1.0)
        case "paleGreen", "苍白的绿色":
            return UIColor(red: 152/255.0, green: 251/255.0, blue:  152/255.0, alpha: 1.0)
        case "darkSeaGreen", "深海洋绿":
            return UIColor(red: 143/255.0, green: 188/255.0, blue:  143/255.0, alpha: 1.0)
        case "limeGreen", "酸橙绿":
            return UIColor(red: 50/255.0, green: 205/255.0, blue:  50/255.0, alpha: 1.0)
        case "lime", "酸橙色":
            return UIColor(red: 0/255.0, green: 255/255.0, blue:  0/255.0, alpha: 1.0)
        case "forestGreen", "森林绿":
            return UIColor(red: 34/255.0, green: 139/255.0, blue:  34/255.0, alpha: 1.0)
        case "green", "纯绿":
            return UIColor(red: 0/255.0, green: 128/255.0, blue:  0/255.0, alpha: 1.0)
        case "darkGreen", "深绿色":
            return UIColor(red: 0/255.0, green: 100/255.0, blue:  0/255.0, alpha: 1.0)
        case "chartreuse", "查特酒绿":
            return UIColor(red: 127/255.0, green: 255/255.0, blue:  0/255.0, alpha: 1.0)
        case "lawnGreen", "草坪绿":
            return UIColor(red: 124/255.0, green: 252/255.0, blue:  0/255.0, alpha: 1.0)
        case "greenYellow", "绿黄色":
            return UIColor(red: 173/255.0, green: 255/255.0, blue:  47/255.0, alpha: 1.0)
        case "darkOliveGreen", "深橄榄绿":
            return UIColor(red: 85/255.0, green: 107/255.0, blue:  47/255.0, alpha: 1.0)
        case "yellowGreen", "黄绿色":
            return UIColor(red: 154/255.0, green: 205/255.0, blue:  50/255.0, alpha: 1.0)
        case "oliveDrab", "橄榄土褐色":
            return UIColor(red: 107/255.0, green: 142/255.0, blue:  35/255.0, alpha: 1.0)
        case "beige", "米色", "浅褐色":
            return UIColor(red: 245/255.0, green: 245/255.0, blue:  220/255.0, alpha: 1.0)
        case "lightGoldenrodYellow", "浅秋麒麟黄":
            return UIColor(red: 250/255.0, green: 250/255.0, blue:  210/255.0, alpha: 1.0)
        case "ivory", "象牙":
            return UIColor(red: 255/255.0, green: 255/255.0, blue:  240/255.0, alpha: 1.0)
        case "lightYellow", "浅黄色":
            return UIColor(red: 255/255.0, green: 255/255.0, blue:  224/255.0, alpha: 1.0)
        case "yellow", "纯黄":
            return UIColor(red: 255/255.0, green: 255/255.0, blue:  0/255.0, alpha: 1.0)
        case "olive", "橄榄":
            return UIColor(red: 128/255.0, green: 128/255.0, blue:  0/255.0, alpha: 1.0)
        case "darkKhaki", "深卡其布":
            return UIColor(red: 189/255.0, green: 183/255.0, blue:  107/255.0, alpha: 1.0)
        case "lemonChiffon", "柠檬薄纱":
            return UIColor(red: 255/255.0, green: 250/255.0, blue:  205/255.0, alpha: 1.0)
        case "paleGoldenrod", "灰秋麒麟":
            return UIColor(red: 238/255.0, green: 232/255.0, blue:  170/255.0, alpha: 1.0)
        case "khaki", "卡其布":
            return UIColor(red: 240/255.0, green: 230/255.0, blue:  140/255.0, alpha: 1.0)
        case "gold", "金":
            return UIColor(red: 255/255.0, green: 215/255.0, blue:  0/255.0, alpha: 1.0)
        case "cornsilk", "玉米色":
            return UIColor(red: 255/255.0, green: 248/255.0, blue:  220/255.0, alpha: 1.0)
        case "goldenrod", "秋麒麟":
            return UIColor(red: 218/255.0, green: 165/255.0, blue:  32/255.0, alpha: 1.0)
        case "darkGoldenrod", "深秋麒麟":
            return UIColor(red: 218/255.0, green: 165/255.0, blue:  32/255.0, alpha: 1.0)
        case "floralWhite", "花的白色":
            return UIColor(red: 255/255.0, green: 250/255.0, blue:  240/255.0, alpha: 1.0)
        case "oldLace", "老饰带":
            return UIColor(red: 253/255.0, green: 245/255.0, blue:  230/255.0, alpha: 1.0)
        case "wheat", "小麦色":
            return UIColor(red: 245/255.0, green: 222/255.0, blue:  179/255.0, alpha: 1.0)
        case "mocassin", "鹿皮鞋":
            return UIColor(red: 255/255.0, green: 228/255.0, blue:  181/255.0, alpha: 1.0)
        case "orange", "橙色":
            return UIColor(red: 255/255.0, green: 165/255.0, blue:  0/255.0, alpha: 1.0)
        case "papayaWhip", "番木瓜":
            return UIColor(red: 255/255.0, green: 239/255.0, blue:  213/255.0, alpha: 1.0)
        case "blanchedAlmond", "漂白的杏仁":
            return UIColor(red: 255/255.0, green: 235/255.0, blue:  205/255.0, alpha: 1.0)
        case "navajoWhite", "Navajo白":
            return UIColor(red: 255/255.0, green: 222/255.0, blue:  173/255.0, alpha: 1.0)
        case "antiqueWhite", "古代的白色":
            return UIColor(red: 250/255.0, green: 235/255.0, blue:  215/255.0, alpha: 1.0)
        case "tan", "晒黑":
            return UIColor(red: 210/255.0, green: 180/255.0, blue:  140/255.0, alpha: 1.0)
        case "burlyWood", "结实的树":
            return UIColor(red: 222/255.0, green: 184/255.0, blue:  135/255.0, alpha: 1.0)
        case "bisque", "浓汤":
            return UIColor(red: 255/255.0, green: 228/255.0, blue:  196/255.0, alpha: 1.0)
        case "darkOrange", "深橙色":
            return UIColor(red: 255/255.0, green: 140/255.0, blue:  0/255.0, alpha: 1.0)
        case "linen", "亚麻布":
            return UIColor(red: 250/255.0, green: 240/255.0, blue:  230/255.0, alpha: 1.0)
        case "peru", "秘鲁":
            return UIColor(red: 205/255.0, green: 133/255.0, blue:  63/255.0, alpha: 1.0)
        case "peachBuff", "桃色":
            return UIColor(red: 255/255.0, green: 218/255.0, blue:  185/255.0, alpha: 1.0)
        case "sandyBrown", "沙棕色":
            return UIColor(red: 244/255.0, green: 164/255.0, blue:  96/255.0, alpha: 1.0)
        case "chocolate", "巧克力":
            return UIColor(red: 210/255.0, green: 105/255.0, blue:  30/255.0, alpha: 1.0)
        case "saddleBrown", "马鞍棕色":
            return UIColor(red: 139/255.0, green: 69/255.0, blue:  19/255.0, alpha: 1.0)
        case "seaShell", "海贝壳":
            return UIColor(red: 255/255.0, green: 245/255.0, blue:  238/255.0, alpha: 1.0)
        case "sienna", "黄土赭色":
            return UIColor(red: 160/255.0, green: 82/255.0, blue:  45/255.0, alpha: 1.0)
        case "lightSalmon", "浅鲑鱼色", "浅鲜肉色":
            return UIColor(red: 255/255.0, green: 160/255.0, blue:  122/255.0, alpha: 1.0)
        case "coral", "珊瑚":
            return UIColor(red: 255/255.0, green: 127/255.0, blue:  80/255.0, alpha: 1.0)
        case "orangeRed", "橙红色":
            return UIColor(red: 255/255.0, green: 69/255.0, blue:  0/255.0, alpha: 1.0)
        case "darkSalmon", "深鲑鱼色", "深鲜肉色":
            return UIColor(red: 233/255.0, green: 150/255.0, blue:  122/255.0, alpha: 1.0)
        case "tomtato", "番茄":
            return UIColor(red: 255/255.0, green: 99/255.0, blue:  71/255.0, alpha: 1.0)
        case "mistyRose", "薄雾玫瑰":
            return UIColor(red: 255/255.0, green: 228/255.0, blue:  225/255.0, alpha: 1.0)
        case "salmon", "鲑鱼色", "鲜肉":
            return UIColor(red: 250/255.0, green: 128/255.0, blue:  114/255.0, alpha: 1.0)
        case "snow", "雪":
            return UIColor(red: 255/255.0, green: 250/255.0, blue:  250/255.0, alpha: 1.0)
        case "lightCoral", "淡珊瑚色":
            return UIColor(red: 240/255.0, green: 128/255.0, blue:  128/255.0, alpha: 1.0)
        case "rosyBrown", "玫瑰棕色":
            return UIColor(red: 188/255.0, green: 143/255.0, blue:  143/255.0, alpha: 1.0)
        case "indianRed", "印度红":
            return UIColor(red: 205/255.0, green: 92/255.0, blue:  92/255.0, alpha: 1.0)
        case "red", "纯红":
            return UIColor(red: 255/255.0, green: 0/255.0, blue:  0/255.0, alpha: 1.0)
        case "brown", "棕色":
            return UIColor(red: 165/255.0, green: 42/255.0, blue:  42/255.0, alpha: 1.0)
        case "fireBrick", "耐火砖":
            return UIColor(red: 178/255.0, green: 34/255.0, blue:  34/255.0, alpha: 1.0)
        case "darkRed", "深红色":
            return UIColor(red: 139/255.0, green: 0/255.0, blue:  0/255.0, alpha: 1.0)
        case "maroon", "栗色":
            return UIColor(red: 128/255.0, green: 0/255.0, blue:  0/255.0, alpha: 1.0)
        case "white", "纯白":
            return UIColor(red: 255/255.0, green: 255/255.0, blue:  255/255.0, alpha: 1.0)
        case "whiteSmoke", "白烟":
            return UIColor(red: 245/255.0, green: 245/255.0, blue:  245/255.0, alpha: 1.0)
        case "gainsboro", "gainsboro":
            return UIColor(red: 220/255.0, green: 220/255.0, blue:  220/255.0, alpha: 1.0)
        case "lightGray", "浅灰色":
            return UIColor(red: 211/255.0, green: 211/255.0, blue:  211/255.0, alpha: 1.0)
        case "silver", "银白色":
            return UIColor(red: 192/255.0, green: 192/255.0, blue:  192/255.0, alpha: 1.0)
        case "darkGray", "深灰色":
            return UIColor(red: 128/255.0, green: 128/255.0, blue:  128/255.0, alpha: 1.0)
        case "gray", "灰色":
            return UIColor(red: 169/255.0, green: 169/255.0, blue:  169/255.0, alpha: 1.0)
        case "dimGray", "暗淡的灰色":
            return UIColor(red: 105/255.0, green: 105/255.0, blue:  105/255.0, alpha: 1.0)
        case "black", "纯黑":
            return UIColor(red: 0/255.0, green: 0/255.0, blue:  0/255.0, alpha: 1.0)
        default:
            return UIColor.blackColor();
    }
}

Web Color 颜色板:

写在后面:

中文名字做了一些调整,尽可能严格依照參照图上的名字做了修正。

英文名保持不变,首字母依旧小写。名字匹配功能会在日后慢慢完好。

时间: 2024-10-12 13:01:48

【iOS】Web Color 的 Swift 实现的相关文章

Web Color 的 Swift 实现

用Swift语言重写Web Color这个类. 这次是用函数实现的,感觉也很简洁.目前(2014.6.28) Xcode 6的方法提示还不健全,就只实现了用颜色名字创建颜色的功能. 最新代码&相关资料下载地址:https://github.com/duzixi/WebColors-with-Swift (持续维护) 用法说明: WebColor.swift文件导入工程,然后直接就可以使用: self.view.backgroundColor =webColor("天蓝色");

[iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01

本文转载至:http://www.cnblogs.com/yangfaxian/p/3765081.html 全书目录: 一.Welcome to Swift 二.Language Guide 三.Language Reference /* 译者的废话: 几个小时前熬夜看了WWDC,各种激动,今年很有料啊!当看到Swift出来的时候,瞬间傻眼,又要学习新语言了.这篇文章来自苹果官方的<The Swift Programming Language>一书,500页左右,在苹果官网有下载.Swift

iOS Web开发

1.让web页面的输入框是数字键盘 ? 1 html 中 input 的 type = "tel" iOS Web开发,布布扣,bubuko.com

iOS 从Objective-C到Swift

前言: 博主功力有限, 也是在学习的过程中, 之前写了几篇在iOS开发中使用Swift进行开发偏向于UI方向的文章, 明显地感觉到OC与Swift的之间的一些区别与联系, 并且还有一些值得注意的地方, 希望看到这篇文章的小伙伴更快地上手Swift. , 最近自己的状态也是很糟糕, 更糟糕的是感冒了(囧~). 有什么错误请评论指出, 谢谢. 一 属性 OC中 我们最常用的property // 常常会这样写 @property (nonatomic, copy) NSString *name; S

Visual Studio Code 支持 iOS Web 应用调试

微软JavaScript Diagnostics项目经理Kenneth Auchenberg在一篇文章中写道,有一个新的Visual Studio Code扩展,允许开发人员直接在他们的Mac和Windows编辑器上调试在iOS设备上运行的JavaScript Web应用和网站. Auchenberg解释说,以前,调试iOS Web应用需要在Mac上运行Safari Web查看器,或者使用一个专用的跨浏览器兼容性检查器,如BrowserStack.新的Visual Studio Code扩展“i

Swift技术之如何在iOS 8下使用Swift设计一个自定义的输入法 (主要是NSLayoutConstraint 的使用)

当前位置: > Swift新手入门 > Swift技术之如何在iOS 8下使用Swift设计一个自定义的输入法 时间:2014-09-10 16:49来源:未知 作者:啊成 举报 点击:562次 我会复习一下有关键盘扩展的内容,然后通过使用iOS 8中的新应用扩展API的设计一个摩斯码的输入法.完成这个教程大约需要花费20分钟.完整代码 概览 通过使用自定义输入法替换系统输入法,用户可以实现一些特别的功能.例如一个特别新颖的输入方式,或输入iOS原生并不支持的语言.自定义输入法的基本功能很简单

Swift 2.0学习笔记——使用Web网站编写Swift代码

Swift 2.0学习笔记--使用Web网站编写Swift代码 Swift程序不能在Windows其他平台编译和运行,有人提供了一个网站swiftstub.com,左栏是代码编辑窗口,右栏是运行结果窗口.可以在任何平台下编译和运行Swift程序.

IOS学习之路——Swift语言(1)——基本类型、运算符与逻辑控制语句

一.变量 变量标识符必须以字符包括Unicode编码字符.美元字符$.下划线_开头,不能以数字开头,不能包含空格.更不能使用关键字命名. swift中变量的声明使用var关键字,常量的声明使用let关键字. 1 var name="Swift"; 2 var version=2.2; 3 let company:String="Apple"; 变量的声明: 1. 可以使用,逗号分割变量来同时声明多个变量 2. 可以使用:类型来同时指明多个变量的类型 在Mac中可以使

iOS开发——图形编程Swift篇&amp;CAShapeLayer实现圆形图片加载动画

CAShapeLayer实现圆形图片加载动画 几个星期之前,Michael Villar在Motion试验中创建一个非常有趣的加载动画. 下面的GIF图片展示这个加载动画,它将一个圆形进度指示器和圆形渐现动画结合.这个组合的效果有趣,独一无二和有点迷人. 这个教程将会教你如何使用Swift和Core Animatoin来重新创建这个效果.让我们开始吧! 基础 首先下载这个教程的启动项目,然后编译和运行.过一会之后,你应该看到一个简单的image显示: 这 个启动项目已经预先在恰当的位置将view