Where should I put background and button image files? Assets or just drag into the app files? - ios

I am making an app but I'm not quite sure where should I put the image files? Just drag and copy inside the app or in assests? What's the difference, I'm not quite sure.

I'd strongly recommend using the xcassets, which you can do by dragging your files onto it when you have it open in Xcode. Xcode handles the rest, copying them into your project. Doing this also allows you do call UIImage(imageNamed:), using the title you give to each Image Set. You also don't have to worry about specific naming of the different size classes, as you drag them to the appropriate section there.

Related

How to override values/file in framework in ios

I have developed the application in ios. It is working fine. I have converted it as a framework(library) so that My codebase remain same.
I have multiple clients for this app. So I need to change the following things
Colors (As it will change the background colors, text colors etc)
Strings (Like headings and labels in some views)
Some files like Images etc
What I want:
As I am android developer, So in that I can create another color file in my client app with same color name, that replaces the color value in Library. and this it just require only one file to be replace and it automatically overrides in library. Same was the case with the String.xml and image files
Looking for something like that as I have described above.
What I searched and found so far:
After searching alot I have found that I need to make outlets public and then I can give them color by accessing them. But What If I have a 1000 of views and 1000s of outlets to make to use this technique, Isnt it better to use it as same way as in android I described above.
Confusions:
Is there anyway in IOS to declare color in a file and to use them in IB and code as well. Well I read about Color.xcassets but that is for ios 11 I think
How to make strings file and to use them in IB and in code. Like strings.xml file in android?
So I short, I want to updated colors,Strings and file per client wise and I do not know how to do it and what is a best way of doing this??
Please help and thanks in advance. Please share your views.
You should configure your framework to read from predefined files in .plist file. this will require only changing the files content in the client application.
Easy way to handle colors and theme using SkinKit. This is too old code. You just reuse idea or create custom themes configuration file(plist,JSON),Strings and images as .bundle read all color and customization from that bundle. So easy to change Colors, Strings and Images assert for various clients.
You seem to have a misconception about what IB is — in particular, what a nib is, and what it means to edit a nib, which is what Interface Builder does. A nib is a file expressing potential instances, typically views. You edit it on your computer using Xcode (IB). When your app runs, the nib is loaded and the views are actually instantiated. That is the only thing you can do with a nib when the app runs. You cannot modify the nib in some way when the app runs; all you can do is load the nib and get the instances.
So, if you want to change all the titles of buttons or all the colors of views when your app runs in accordance with some configuration file, you can do that, but that has nothing to do with nibs or IB. You would just load the nib as usual to get the views, and then change them all, one by one, in code. You could use tags or some other identification mechanism to help you find each view, but that would be entirely up to you to work out.

Share image resources between app and today widget

Can I share resources (images that are compiled into the application) between my main iOS app and my today extension widget? Say I create a new application. Then add a today extension project to the solution. And then I create a UIImageView. I want to reference an image from a shared pool of images rather than having 2 of every image, one added to main app and another added to widget app.
imageView.Image = UIImage.FromBundle("IMG_3799.JPG");
The IMG_3799.JPG is inside the main application in the References folder of that project. I'd prefer the same image asset to be referenced by the widget. Is that possible? Currently, i'm making a 2nd copy of IMG_3799.JPG and putting it into the widget.
Out of box, you can't.
The closest thing to that would be to create an app group that contains the main app and the extension and that has access to the common folder. However you can't place any file there during deployment, just during runtime, so it may or may not be a workaround for what you require, but that is the only way.
I'm afraid this might be late. Following is what I did with Xcode 12.4
First, go into your Assets.xcassets file in Xcode then select the image you want to be shared.
Second, click "Hide or show the Inspectors" in the top right corner of Xcode.
Thir, click "Show the file inspector"
Then you should see Target Membership where you can simply click the checkbox to have the images to be used in main app, extensions, etc.
I found this method for Wigetkit from 17:10 of this youtube video: https://www.youtube.com/watch?v=ZzBBDrFNXmk
I came across this answer while looking for a way to share images between my main app and my iMessage extension. As it turns out, just by adding the image files to both targets I was able to use one single copy of my images in both places.
In the project navigator, I added the images to a folder (not .xcassets) under my main project (not the extension) and just ensured that the Target Membership was set to both the main app and extension.

Add many images to xcodes asset catalog - how to manage naming and 1x,2x,3x for each?

I have an app where I would like to add many images (500+) to xcode's asset catalog. Adding the 1x images was easy, I simply had to drag the first folder. However to add the 2x and 3x images it seems I would need to drag each image in manually, and I'd prefer not to do that. The 3 different sizes for each image are all named the same, w/ just different sizes. Is there anyway to automate this process?
You can named image something like : yourimg.png, yourimg#2x.png, yourimg#3x.png ,so it's become one set. Let's take another : dogImg.png, dogImg#2x.png, dogImg#3x.png then this is second set.
So, you can name images like this and put every images to one single folder.
Then you simply drag and drop that folder to xcode, and you have done!
No need to use assets in this case! this naming conversion manage same as assetts.!
Refer Raywebderlich's one tutorial's portion where they are adding images like this.
OR (recommended way - because it is using assets)
Name your images like - test#1x.png, test#2x.png, test#3x.png and drag all them in to the assets and it will automatically take place at proper location. That's it!!
You can maintain folder structure also. For example If you have folder structure like below screen shot,
and If you drag and drop whole Images folder to assets then xcode will manage everything for you(see result in below screenshot) but you just need to keep in mind that follow the naming standard for the images like test#1x.png, test#2x.png, test#3x.png. You can ignore # for 1x image, I mean your image set can be like test.png, test#2x.png, test#3x.png also!
Screenshot of assets after dragging Images from the finder,
Happyxcasset is a python script that easily imports resource files into xcassets in Xcode.
https://github.com/qdvictory/happyxcasset
You will like it.

Adding new language to existing localized app

I have an app that uses localization, I need to add one more language, I want to display two different language images of same name in one xib file, the xib file is not localized as I am localizing the images. Can it be done using interface builder, without writing any code?
You can add one more language by click on + button.Hope this will help you.But you have to make multiple XIB's as you are saying to set the images only in one XIB i think it is not possible.
Add the images to your localized subdirectories in your project (en.lproj, es.lproj, etc.) and iOS will pick up the correct image when it unarchives the localized xib file.
Xcode can do this for you automatically: Just select the resource you want to localize (an image, xib file, etc.), display the File Inspector pane, and then click the Localize button.
(As a side note, it's a bad practice to localize a high number of images. You should remove text from images and choose them so they are "neutral" and "understandable" in every region of the world. Your app size will thank you for it.)
To do it without code you must localize the xibs, otherwise you will require code from you or others and some configuration. It's easier as follows:
Assuming you have added already localizations to the project (you can do it in Project > Info tab) you just need to select the image in the project tree and check the desired localizations in the right sidebar (cmd-alt-1, localizations).
Replace the image in each *.lproj directory with the localized version. Then in your viewDidLoad use -[UIImage imageNamed:] as usual to load an image into the xib image view or whatever you are doing.

Resources located in a separate bundle visible in IB, but not in the runtime

I have an application, where most of image resources are stored in the separate resource bundle (there is a valid reason to do that). This resource bundle is added to the project along with main application bundle and while I design my NIB in the Interface Builder all those images are visible inside the IB (i.e. they appear in the drop list for my UIImageView and they are properly displayed in my UI). However when I run my app in the simulator all those images are missing. Is there a way to tell UIKit to look for those images inside this additional resource bundle in addition to the main application bundle?
I can load those images manually in viewDidLoad no problem, but I'm looking for a way to use Interface Builder to make it easier to change design/skin of those NIBs.
Update: While image files from that bundle are available right in the drop list in the IB, they won't load in runtime. However if I prefix their names with a bundle name in IB like this:
Then they will load properly in the runtime, but IB will display them as big blue question marks.
Now the question is - how to have best of the both worlds and have images displayed properly both in IB (design-time) and runtime.
I ran into the same problem, and it's likely due to the way that Xcode is compiling your images when assembling your bundle target. Since bundle targets aren't fully supported on iOS, you have to create them as Mac OS X targets. That leaves a problematic build setting in place, namely COMBINE_HIDPI_ARTWORK, which will be set to YES. This results in your normal and #2x variants being combined into a single tiff file in your bundle. The resulting file is supported on Mac OS but not iOS.
(Thanks to this answer for the tip).
To fix this, select your bundle-creating project in the File Navigator, select your bundle target, switch to the Build Settings tab, and search for the aforementioned setting. Then either select the whole row and tap Delete or just set it to NO.
At that point you should be able to use your images in both IB and code without doing anything special (other than making sure the .xib and image are in the same bundle).

Resources