twui icon indicating copy to clipboard operation
twui copied to clipboard

TUIImage imageName could not accept image name without extention

Open slavikshen opened this issue 11 years ago • 0 comments

The imageName method in TUIImage could not accept the image name without ext. The NSImage or UIImage could auto complete the image name with png and @2x according to the environment.

I suggest the following change. It works well for me.

+ (TUIImage *)imageNamed:(NSString *)name cache:(BOOL)shouldCache
{
    if(!name)
        return nil;

    static NSMutableDictionary *cache = nil;
    if(!cache) {
        cache = [[NSMutableDictionary alloc] init];
    }

    TUIImage *image = [cache objectForKey:name];
    if(image)
        return image;

    NSImage* nsImage = [NSImage imageNamed:name];
    if(!nsImage)
        return nil;

    NSData* data = [nsImage TIFFRepresentation];
    if(data) {
        image = [self imageWithData:data];
        if(image) {
            if(shouldCache) {
                [cache setObject:image forKey:name];
            }
        }
    }

    return image;
}

slavikshen avatar Jan 24 '13 06:01 slavikshen