Date
Sep. 8th, 2024
 
2024年 8月 6日

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();
    UIGraphicsEndImageContext();

    return result;
}

- (instancetype)copy {
    return [UIImage decode:self];
}
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
程序猿、设计师、奇怪的博主。
苹果死忠、热爱色彩斑斓的世界。
如有意向请随时 与我联系