I'm using Xcode (objective-C) with UIKit and SpriteKit.
I imported an image (.png or .jpeg) into my xCode project by "adding a file to (project)" and I put the image in my supporting files.
I think I figured out how to create a UIView in the didMoveToView part of my code in one of my .m files:
CGRect viewRect = CGRectMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame), 100, 100);
UIView* View1 = [[UIView alloc] initWithFrame:viewRect];
but I'm not sure how to attach an image (the .png or .jpeg [doesn't matter] ) to the UIView and display it when the program compiles.
Can someone please tell me how to do this?
Or, if there is a better way to import a picture to Xcode and use it only during the given .m file could someone please tell me how to do this?
Use a UIImage when coding for it, and use that control in the view. You can actually set the image in the design window and not even have to code it one bit.
If you're developing for a Mac, use an NSImage.
If you want to code for it, use an outlet to refer to it, and use actions if you want a user to be able to perform actions with it.
In order to do this (in the newest Xcode), click the button that looks like a Venn Diagram, so that way both your storyboard and your .m file show up. When you want to make an outlet or action, control-click and drag. Don't Command-click, don't option-click, it's control-click. Connect the lines and you'll have a pop-up, and it'll make a function/outlet for you.
Best of luck! :)
Related
I tried to find the solution, but I couldn't find anyone with the same problem.
I'm using Xcode 8.2.1, writing in Objective-C.
I'm actually having a problem with adding a UIImageView to IBOutletCollection. I'm trying to do it using the Interface Builder.
dragging to connect ImageView with the Collection
I've already deleted any existing outlets of that ImageView.
I'm also adding screenshot of the header file of the MasterViewController - I guess everything is OK here.
declaration of the collection
Thanks for help.
You have to use IBOutletCollection(UIImageView) instead of IBOutletCollection(UIViewController)
i'm very new to xcode. i've googled this and even serched here and i didn't find exactly what i was looking for. i really wanna get this. especially since it's the most basic thing there is.
so, i have the .h and .m files
i want to DRAG a uiview into the .xib file, i don't want it to be as big as the screen, so i resize it.
now i want to draw a bunch of rectangles INSIDE this view object.
how do i go about doing this?
your help would be greatly appreciated!
So you add a generic UIView then create a subclass of UIView and do your drawing inside the drawRect method.
Then change the class of the UIView to your subclass name in the inspector.
Be sure to #include your header in the app delegate.
That's the basic thing.
For more sophistication, you're going to want to learn to use UIViewController subclasses as well. These are used all over ios.
I am trying to implement the OBShapedButton class in my iOS project so I can create irregular shaped buttons defined by png files. This is a link for more information on OBShapedButton.
Basically this class works great when I'm using it with my nib files. However I prefer using storyboard in my projects. But when I try to do the same thing in storyboard, following all the same steps for making an irregular button as I do in my nib files, it doesn't work and the clickable area is still defined by a rectangle and not my png image.
My question is how would I go about using storyboard with OBShapedButton? Is there something I am missing about storyboard that would prevent OBShapedButton from working?
I'm using it in a project with Storyboards. Be sure the set the Custom Class in the Identity inspector to OBShapedButton, I don't think I did anything else special.
I am trying to load a UIView inside another view.
view01 is set to take 50% vertical space on the main view. view01 is attached to an outlet. I will be using view01 to load various views on top of it. Now I am able to load view02 from an alternate xib file.
The problem is that sometimes it works and some times it doesn't. And it's doing this without any change to the data used in the app. So I am wondering what could be the reason for this intermittent problem?
This is the code to load:
statsView = [[StatsViewController alloc] initWithNibName:#"StatsViewController" bundle:nil];
[statsView setRiftIndex:riftIndex.characterSheet];
[statsView activateEditing:NO];
[listView addSubview:statsView.view];
Can't post images yet :(
The StatsViewController.xib has the StatsViewController class as the file-owner in the xib.
I finally found the problem. there was 2 xib files with the same name, one was from a previous test I had done. and the linker would alternate from one to the other every time I ran it. I was sure I had deleted the file before but it seams I had only removed the reference.
I created a UIButton in my app.xib file. I connected it to "IBOutlet id button;" within the app.h file. For some reason when I start typing in the app.m file "butt..." it doesn't find the the id button.
The thing is, that I have another xib file in this project with the same implementation where there is no problem finding in the m file the id buttons connected from the h file to the xib file.
Anyone has any idea what I may be missing here?
If you've created the outlet using the drag to Assistant Editor feature, it is possible that the ivar created is _button in which case you either use self.button or _button.