KSImageNamed是一个使XCode可以预览项目中图片的插件,只需编写代码[NSImage imageNamed:,XCode自动列出项目中图片列表,并提供预览功能。如图:
项目地址为
https://github.com/ksuther/KSImageNamed-Xcode 。
但是在项目中,用户往往会使用一些宏定义如UIImageNamed(NSString *name),UIImageLoad(name, type),笔者比较喜欢用,相关宏定义文件到这里查看,我们能不能在编写代码UIImageNamed(时也能自动提示呢(当然可以,不行的话笔者就不写这篇文章了),好,看看笔者是如何做的:
可能你也注意到了,这个项目中配置关键字的文件是 Completions.plist;代码如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <dict> <key>classAndMethod</key> <string>mage imageNamed:</string> <key>methodDeclaration</key> <string> imageNamed:</string> <key>methodName</key> <string>imageNamed</string> <key>comment</key> <string>Standard NSImage/UIImage method</string> </dict> <dict> <key>classAndMethod</key> <string>prite spriteWithFile:</string> <key>methodDeclaration</key> <string> spriteWithFile:</string> <key>methodName</key> <string>spriteWithFile</string> <key>comment</key> <string>cocos2d's CCSprite</string> </dict> <dict> <key>classAndMethod</key> <string>priteFrame frameWithImageNamed:</string> <key>methodDeclaration</key> <string> frameWithImageNamed:</string> <key>methodName</key> <string>frameWithImageNamed</string> <key>comment</key> <string>cocos2d's CCSpriteFrame</string> </dict> <dict> <key>classAndMethod</key> <string>ode spriteNodeWithImageNamed:</string> <key>methodDeclaration</key> <string> spriteNodeWithImageNamed:</string> <key>methodName</key> <string>spriteNodeWithImageNamed</string> <key>comment</key> <string>SpriteKit's sprite node</string> </dict> <dict> <key>classAndMethod</key> <string>ure textureWithImageNamed:</string> <key>methodDeclaration</key> <string> textureWithImageNamed:</string> <key>methodName</key> <string>textureWithImageNamed</string> <key>comment</key> <string>SpriteKit's SKTexture</string> </dict> </array> </plist>
我们在</array>前面添加
<dict> <key>classAndMethod</key> <string>UIImageNamed(</string> <key>methodDeclaration</key> <string>(</string> <key>methodName</key> <string>UIImageNamed</string> <key>comment</key> <string>Custom UIImageName method</string> </dict> <dict> <key>classAndMethod</key> <string>UIImageLoad(</string> <key>methodDeclaration</key> <string>(</string> <key>methodName</key> <string>UIImageLoad</string> <key>comment</key> <string>Custom UIImageLoad method</string> </dict>
保存,运行项目,重启XCode,现在支持我们自定义的方式了。如果你使用其他宏定义,按照这个方法添加配置信息就可以了。
Xcode6 自动提示图片 KSImageNamed 支持自定义 UIImageNamed(name),UIImageLoad(name, type)方法
原文地址:http://blog.csdn.net/yanglishuan/article/details/39995145