Jul. 21st, 2024
2024年 6月 16日

Post: iOS: Copy UIColor

iOS: Copy UIColor

Published 12:09 Sep 12, 2014.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

UIColor 实例默认是不支持 copy 操作的, 但有时候我们还是需要这样的操作, 怎么实现呢?

// @implementation UIImage (Copying)
+ (UIImage *)decode:(UIImage *)image {
    if (image == nil) {
        return nil;

    UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
    [image drawAtPoint:CGPointZero];
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();

    return result;

- (instancetype)copy {
    return [UIImage decode:self];
Pinned Message
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF