UIColor to Hexadecimal (web color)

后端 未结 5 1505
悲&欢浪女
悲&欢浪女 2021-02-15 23:37

Is there an easy way to convert UIColor to a hexadecimal value ?
Or do we have to get the RGB components with CGColorGetComponents and then work it

5条回答
  •  轮回少年
    2021-02-16 00:09

    There isn't, as far as I know, any built in solution.
    Note however, that you should multiply by 255 instead of 256.

    Getting an hexadecimal representation is an easy task, so you won't have many troubles to build the string manually.

    NSLog(@"%X%X%X", redInteger, greenInteger, blueInteger);
    

提交回复
热议问题