I have a couple of images in my Resources directory of my iphone project. I want to set one of those images for an UIImageView.
After adding the images to XCode project and correctly setting their targets to the project, Interface builder is not showing the images to select it in Attributes property of UIImage view. Do I have to refresh the Inspector? Am I missing some step?
If you are using Xcode 3 then I think you have to save all changes and then close Interface Builder and re-open it in order for it to see those changes. Also I would highly recommend moving to Xcode 4 if you are not already using it.
Related
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.
I am using share extension with custom UI, So I configured my view controllers in storyboards, and add image (and tried add background image) to the button. So in storyboard I see that image. But when I run extension I don't see image on the button.
So the issue is because seems I don't add my images to the new target. So if you create a new target, and extension it's our new target we should be sure that all needed resources like images, strings are added to it.
So just use target membership to checkmark needed files or add it via xcode project "Build Phases" tab.
So it's also connected to other classes you want to use. Sometimes can be a pain to add all of them because some classes import other classes and etc.
sometimes when I start my App it shows me a black screen until its loaded.
Where is the place to add an Image or whatever to show that in instead of that nasty black screen?
Thanks in advance,
Philip
The black screen simply means that there is no launch image set for your app. The newest and in my opinion easiest way to add these is to use an Asset catalog.
If you created your app in a recent version of xCode, an asset catalog named Images.xcassets is automatically created for you.
Navigate to the same by clicking on it and then simply drag and drop your image into the same.
Here's a screenshot:
I would also strongly recommend that you maintain all graphics used in your app via this Asset catalog. The big advantage with using this process is you don't have to worry about the usual naming conventions you would need if you included graphics outside of an asset catalog - for e.g. You no longer have to name retina images as #2x
Something really simple in fact. Go to Xcode, Tap the project on the top, on the drop down menu on the top left select the target, then click General and select images at where it says Launch Images
link to a video with bug
I simply created a project in xCode. Then I added any UI element to a view. Then I tried to resize this item to left and to right. No code, Interface Builder was used only.
I have checked with some types of projects for iOS and with UILabel and UIButton. The result is the same: when I try to resize the item from the left then it moves the parent view/viewcontroller instead.
Uncheck "Siblings and Ancestors" under Resizing Behavior in Xcode 5 Storyboard.
Voila! As such, resizing your UI elements will not cause your view controllers to move.
You need to uncheck the "Siblings and Ancestors" in your .xib/.storyboard file. See below screenshot of how to toggle this behavior on and off:
As has been said before, you must uncheck the "Siblings and Ancestors" option under Resizing Behavior in the Xcode 5 Storyboard.
The specific purpose of this feature is to be able to resize large groups of objects all at once. For instance, lets say that you have a Table View and you resize one of the cells. In this case, it would seem petty, since you would just have to resize the Table View Controller, but it becomes extremely handy once you have layered objects such as that.
Sorry for the somewhat duplicate answer, but you did ask for an explanation of why a feature like that would be added.
Additionally I have found out that another computer with the same version of xCode works with the same copy of project normally.
I didn't know how to solve this problem without uninstalling of xCode.
So I uninstalled it using AppCleaner and installed it again.
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).