Reputation: 123
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?
Upvotes: 0
Views: 954
Reputation: 1443
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! :)
Upvotes: 1