网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 ios中十六进制的颜色转换为uicolor
范文
    可用类别写一个 方便使用
    + (uicolor *) colorwithhexstring: (nsstring *)color
    {
    nsstring *cstring = [[colorstringbytrimmingcharactersinset:[nscharactersetwhitespaceandnewlinecharacterset]] uppercasestring];
    // string should be 6 or 8 characters
    if ([cstring length] <6) {
    return [uicolorclearcolor];
    }
    // strip 0x if it appears
    if ([cstring hasprefix:@0x])
    cstring = [cstringsubstringfromindex:2];
    if ([cstring hasprefix:@#])
    cstring = [cstringsubstringfromindex:1];
    if ([cstring length] !=6)
    return [uicolorclearcolor];
    // separate into r, g, b substrings
    nsrange range;
    range.location =0;
    range.length =2;
    //r
    nsstring *rstring = [cstring substringwithrange:range];
    //g
    range.location =2;
    nsstring *gstring = [cstring substringwithrange:range];
    //b
    range.location =4;
    nsstring *bstring = [cstring substringwithrange:range];
    // scan values
    unsigned int r, g, b;
    [[nsscannerscannerwithstring:rstring] scanhexint:&r];
    [[nsscannerscannerwithstring:gstring] scanhexint:&g];
    [[nsscannerscannerwithstring:bstring] scanhexint:&b];
    return [uicolorcolorwithred:((float) r /255.0f) green:((float) g /255.0f) blue:((float) b /255.0f) alpha:1.0f];
    }
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/22 1:05:07