Plist file parsing Example: Getting a plist file width and height of sprite animation

Original link: http://www.cnblogs.com/yang3wei/archive/2012/02/17/2739919.html

// used to get sprite width and height, too fucking egg pain ~

- ( CGSize ) getAnimSpriteSize :( NSString *) {animName

NSString *plistPath = [[NSBundlemainBundle] pathForResource:animNameofType:@"plist"];

NSDictionary *dictionary = [NSDictionarydictionaryWithContentsOfFile:plistPath];

NSDictionary *framesDic = [dictionaryobjectForKey:@"frames"];

        NSString *firstFrameName = [NSStringstringWithFormat:@"%@0.png", animName];

NSDictionary *firstFrameDic = [framesDicobjectForKey:firstFrameName];

NSString *rectDataString = [firstFrameDicobjectForKey:@"frame"];

NSRange range =NSMakeRange(1, [rectDataStringlength]-2);

NSString *withoutBorder = [rectDataStringsubstringWithRange:range];

NSArray *array = [withoutBordercomponentsSeparatedByString:@", "];

NSString *sizeString = [arrayobjectAtIndex:1];

NSRange range2 =NSMakeRange(1, [sizeStringlength]-2);

NSString *sizeStringWithoutBorder = [sizeStringsubstringWithRange:range2];

NSArray *size = [sizeStringWithoutBordercomponentsSeparatedByString:@","];

returnCGSizeMake([[size objectAtIndex:0]intValue], [[size objectAtIndex:1]intValue]);

}

Reproduced in: https: //www.cnblogs.com/yang3wei/archive/2012/02/17/2739919.html

Guess you like

Origin blog.csdn.net/weixin_30565199/article/details/94782699