Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

TUIImage imageName could not accept image name without extention #131

Open
slavikshen opened this issue Jan 24, 2013 · 0 comments
Open

TUIImage imageName could not accept image name without extention #131

slavikshen opened this issue Jan 24, 2013 · 0 comments

Comments

@slavikshen
Copy link

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;
}
mralexgray referenced this issue in mralexgray/twui Apr 2, 2013
…ment

Fix TUINSView trackingView memory management
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant