xcode Xcode5 xcassets - how to bulk replace images?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19006610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode5 xcassets - how to bulk replace images?
提问by Mete
Say I have a project with 100 images that I've imported into a folder inside the main Images.xcassets file. Then I go and get updates for 67 of those images from my graphics designer - is there an easy way to push those image updates into the xcassets folder?
Say I have a project with 100 images that I've imported into a folder inside the main Images.xcassets file. Then I go and get updates for 67 of those images from my graphics designer - is there an easy way to push those image updates into the xcassets folder?
As it stands, I'm opening the xcassets file in Xcode, and for each of the images that's changed I'm dragging the new image into the little 2x or 1x box - I have to do that 67 times! I can't just drag/drop the files in Finder (the old way) because every image in the xcassets folder has its own subfolder. If I don't use the xcassets file for my images, I can easily update the files by doing this. But xcassets are supposed to "make managing your assets much simpler."
As it stands, I'm opening the xcassets file in Xcode, and for each of the images that's changed I'm dragging the new image into the little 2x or 1x box - I have to do that 67 times! I can't just drag/drop the files in Finder (the old way) because every image in the xcassets folder has its own subfolder. If I don't use the xcassets file for my images, I can easily update the files by doing this. But xcassets are supposed to "make managing your assets much simpler."
Fine - so what am I missing?
Fine - so what am I missing?
采纳答案by Filip Radelic
I don't think you're missing anything. Assets folders are simply not well thought through. They introduce a few benefits, but a lot more flaws.
I don't think you're missing anything. Assets folders are simply not well thought through. They introduce a few benefits, but a lot more flaws.
Take for example launch image. You can't set the same retina and retina 4-inch launch images for different iOS versions via assets without Xcode duplicating the files. I guess we have no other option but to submit enhancement requests via bug reporterand hope...
Take for example launch image. You can't set the same retina and retina 4-inch launch images for different iOS versions via assets without Xcode duplicating the files. I guess we have no other option but to submit enhancement requests via bug reporterand hope...
回答by user3199112
No need for Ruby, you can run this shell script to find files in a originfolder (where your updated images are), find files with the same name in your destinationfolder (.xcassets folder) and overwrite them with the updated version. Works great!
No need for Ruby, you can run this shell script to find files in a originfolder (where your updated images are), find files with the same name in your destinationfolder (.xcassets folder) and overwrite them with the updated version. Works great!
find ORIGIN FOLDER PATH NAME -name '*.png' | while read f; do f2=$(find DESTINATION FOLDER PATH -name "${f##*/}"); [[ $f2 ]] && cp "$f" "$f2"; done
回答by Shirish Gone
i wrote a ruby script to automate this task. Please follow the below link. https://gist.github.com/shirishgone/8036382
i wrote a ruby script to automate this task. Please follow the below link. https://gist.github.com/shirishgone/8036382
回答by rjferguson
I've started setting aside images like the launch image and app icons in a separate folder within my xcassets file, since those images rarely change. Then, whenever I need to re-import images, or add new ones, I delete the existing images (excepting the separate folder), and re-import everything (excepting the images I set aside). It works cleanly, and doesn't break any of my code or storyboards.
I've started setting aside images like the launch image and app icons in a separate folder within my xcassets file, since those images rarely change. Then, whenever I need to re-import images, or add new ones, I delete the existing images (excepting the separate folder), and re-import everything (excepting the images I set aside). It works cleanly, and doesn't break any of my code or storyboards.
Or, you can drag and drop in finder, you just have to open the .xcassets folder in Finder and put the images in the correct directories/imagesets. Xcode is changing the directory structure, and similarly to the past, if the images keep their same filename, you can overwrite them in the Finder and Xcode will update. You don't need to mess with the .xcassets file in Xcode for a simple change like this, though it is a bit of a pain to drag each image into the appropriate image set, and a script could make things much easier in this area.
Or, you can drag and drop in finder, you just have to open the .xcassets folder in Finder and put the images in the correct directories/imagesets. Xcode is changing the directory structure, and similarly to the past, if the images keep their same filename, you can overwrite them in the Finder and Xcode will update. You don't need to mess with the .xcassets file in Xcode for a simple change like this, though it is a bit of a pain to drag each image into the appropriate image set, and a script could make things much easier in this area.
回答by Seamus
I did not find a quick way, so I wrote one myself. Based on python. Enjoy. https://github.com/qdvictory/happyxcasset
I did not find a quick way, so I wrote one myself. Based on python. Enjoy. https://github.com/qdvictory/happyxcasset