Unable to change background of new view when using spritekit [duplicate] - ios

So i've changed the background property of my default view in my storyboard file to as many as the colours in the rainbow. The colour shows up along with my buttons nicely in Xcode, but when I actually RUN the app, the background is always the same, ugly, default grey colour that you start with a new Xcode project ("Hello World!").
I've searched up for the answer all over Google and to no avail. Am I doing something wrong or is it just a glitch? It might be also important to mention than i'm using Spritekit, and that this "view" is the only view in my Storyboard file, the default one. Should I change self.view to skView? Would that work?
Oh and also, when I manually try to change the background colour under viewDidLoad in my .m class by doing:
self.view.backgroundColor = [UIColor backgroundColor];
the background STILL doesn't change and is always the same default colour. Please help me... i'm desperate right now... there's no answers anywhere to be found. Thanks.

All Storyboard, all graphical answer:
Explanation: You should modify the Main.storyboard, select the View Controller, change View in the Attribute Inspector, and apply a new Background color.
With exactly 0 lines of code, you should get this result:
Download project here.

I found myself in the same exact problem. After finding no help whatsoever online and exhausting myself trying different things; I decided to simply add a view to the storyboard and make it the background. This way you can change the background color and/or image and it will show up. It should be entirely constrained to the superview. I used the following constraints:
If you need to add other things to the storyboard (which it wouldn't really make any sense if you didn't) every other object should be contained in this view (it basically replaces the superview). This works well for me and I hope it can help someone else too.

Just try checking that you don't have a line saying 'self.view.backgroundColor = ...' inside of your .m file. i.e. somewhere in 'loadView:', 'viewDidLoad:' or 'viewWillAppear:'
(I first thought that you have linked to some different viewController inside of your storyboard, but if you have all your buttons displaying correctly, then this assumption is wrong)
If you just want a quick fix of the problem, then simply add a line in your .m file saying self.view.backgroundColor = [UIColor yellowColor];

The UIView.backgroundColor property is inherited by SKView, but is visible only if the SpriteKit view isn't rendering any SpriteKit scene.
Of course, in practice a SpriteKit view just about always has an SKScene assigned to it. When the view is rendering a scene, it paints itself with the backgroundColor of whatever scene it's assigned to render.
(This means that if you present a different scene, the background will change. It also means that if your scene's scaleMode and size are such that the scene doesn't fill the entire view, the view's backgroundColor will be visible in areas not covered by the scene.)
You can set an SKScene's background color in code using its backgroundColor property. If you create your scene graphically in an .sks file, you can set it in the inspector pane in Xcode:
IMPORTANT: This is the SpriteKit Scene inspector, seen when you edit a .sks file in Xcode -- not the view / view controller inspector that you see when editing a storyboard.

If you have the same problem as me! That you see the ugly gray background right after the SplashScreen, I have found a solution! Just after creating the skView, create an empty scene with a white background and present it directly!
let backgroundColoredScene = SKScene()
backgroundColoredScene.backgroundColor = SKColor.white()
skView.presentScene(backgroundColoredScene)

I had the same problem. Try to change the background color at main.storyboard as above, then restart Xcode.

The issue is with the SKView. A workaround I use is to change the SKView on the storyboard to a UIView. Then transition to an ViewControler with an SKView when you want to run your spritekit game.
Here's where you can change the view type on the storyboard

Related

Why doesn't the background colour of my Storyboard in Xcode change? It's always the same grey color?

So i've changed the background property of my default view in my storyboard file to as many as the colours in the rainbow. The colour shows up along with my buttons nicely in Xcode, but when I actually RUN the app, the background is always the same, ugly, default grey colour that you start with a new Xcode project ("Hello World!").
I've searched up for the answer all over Google and to no avail. Am I doing something wrong or is it just a glitch? It might be also important to mention than i'm using Spritekit, and that this "view" is the only view in my Storyboard file, the default one. Should I change self.view to skView? Would that work?
Oh and also, when I manually try to change the background colour under viewDidLoad in my .m class by doing:
self.view.backgroundColor = [UIColor backgroundColor];
the background STILL doesn't change and is always the same default colour. Please help me... i'm desperate right now... there's no answers anywhere to be found. Thanks.
All Storyboard, all graphical answer:
Explanation: You should modify the Main.storyboard, select the View Controller, change View in the Attribute Inspector, and apply a new Background color.
With exactly 0 lines of code, you should get this result:
Download project here.
I found myself in the same exact problem. After finding no help whatsoever online and exhausting myself trying different things; I decided to simply add a view to the storyboard and make it the background. This way you can change the background color and/or image and it will show up. It should be entirely constrained to the superview. I used the following constraints:
If you need to add other things to the storyboard (which it wouldn't really make any sense if you didn't) every other object should be contained in this view (it basically replaces the superview). This works well for me and I hope it can help someone else too.
Just try checking that you don't have a line saying 'self.view.backgroundColor = ...' inside of your .m file. i.e. somewhere in 'loadView:', 'viewDidLoad:' or 'viewWillAppear:'
(I first thought that you have linked to some different viewController inside of your storyboard, but if you have all your buttons displaying correctly, then this assumption is wrong)
If you just want a quick fix of the problem, then simply add a line in your .m file saying self.view.backgroundColor = [UIColor yellowColor];
The UIView.backgroundColor property is inherited by SKView, but is visible only if the SpriteKit view isn't rendering any SpriteKit scene.
Of course, in practice a SpriteKit view just about always has an SKScene assigned to it. When the view is rendering a scene, it paints itself with the backgroundColor of whatever scene it's assigned to render.
(This means that if you present a different scene, the background will change. It also means that if your scene's scaleMode and size are such that the scene doesn't fill the entire view, the view's backgroundColor will be visible in areas not covered by the scene.)
You can set an SKScene's background color in code using its backgroundColor property. If you create your scene graphically in an .sks file, you can set it in the inspector pane in Xcode:
IMPORTANT: This is the SpriteKit Scene inspector, seen when you edit a .sks file in Xcode -- not the view / view controller inspector that you see when editing a storyboard.
If you have the same problem as me! That you see the ugly gray background right after the SplashScreen, I have found a solution! Just after creating the skView, create an empty scene with a white background and present it directly!
let backgroundColoredScene = SKScene()
backgroundColoredScene.backgroundColor = SKColor.white()
skView.presentScene(backgroundColoredScene)
I had the same problem. Try to change the background color at main.storyboard as above, then restart Xcode.
The issue is with the SKView. A workaround I use is to change the SKView on the storyboard to a UIView. Then transition to an ViewControler with an SKView when you want to run your spritekit game.
Here's where you can change the view type on the storyboard

PaintCode - update view and pass variables

Does anyone know of a comprehensive tutorial on implementation of PaintCode, using variables with it, and getting the view to update. I am struggling my way through it. I have built a custom class, and linked a view controller, with a UIView, and I can see the simple graph I made. I have linked it up so that it is #IBDesignable & #IBInspectable and both work fine. I am just not sure how to pass a variable through to the UIView.
I also have absolutely no idea how to get the thing to update when the variable changes.
Any assistance in this would be great, it has taken all day so far and I feel nowhere closer to solving the issue.
I do appreciate your time and effort.
There a many tutorials in PaintCode home page and at this other website, good lucky
However to access the values you create you just need to create an outlet from the UIView to your UIViewController class and class myViewName.myVariableName = myValue
As this step by step tutorial explain
The only tutorials I've found are the PaintCode website.
There are three things that I tend to adjust when trying to add/remove parameters to make my drawings more customizable via code.
When you click on a canvas, there is a drop down menu in the inspector that allows you to include a draw method, an image method, or both when you export the style kit.
When selecting the color in the color palette, there is a drop down menu in the upper right that allows you to make the color a parameter, so that when you export, you can set the color via code.
Add a frame to the canvas and set the constraints in the inspector. These constraints are the old style layout constraints that are very annoying, but doing this inserts a rect parameter in the exported methods which you can set in the code as well.
I don't know any other good PaintCode tutorials - over and above - the tutorials suggested. But after some research, I think I know the answer to your problem:
Background before the answer: I had the same problem. For example, you have a good sized image (created by PaintCode) that works on all iPhone device except the iPhone 4S.
To solve my issue:
Open PaintCode & find the “Frame” button.
Learn a new word “Parametric”. That is what we are dealing with. When the frame changes in size, you set whether the objects inside the frame change size or stay the same.
Watch the Dynamic Shapes tutorial on the PaintCode site. All of the answers are within this short youTube video. It took 5 times of watching it until I have extracted all of the information I needed to get it to work.
If you want the more details, keep reading:
#IBDesignable
class beerViewClass: UIView {
override func drawRect(rect: CGRect) {
SecurityStyleKit.drawCarDashboard(frame: self.bounds, wageIncome: "yo!")
}
}
Notice I can set the frame size as I have multiple views of the same image. Also I can send in variables to the drawCarDashboard.
Within PaintCode, put the objects you want to scale / shrink inside the frame.
Set the Springs and Struts for each item in the frame. For example, do you want it to shrink, stay vertically centered, etc.
Export your StyleKit to Xcode.
in Xcode, using Storyboard or code, add the UIViews to your View
Controller
Add a new Swift file.
Change the blank Swift file to a subclass of UIView & add code (see example)
In storyboard view, select the views that were added.
Set the view to the class you wrote (beerView)
I hope that helps. I hope my explanation was clear.

How to make the buttons visible on simulator?

I'm using Xcode 5.1.1. I recently added a background image to my application but the buttons on the view controller aren't visible. When I remove the background image, the buttons become visible again. How to handle this?
If you are not checking the view hierarchy, then do one thing create outlet of you button and then write following code in viewDidLoad.
[self.view bringSubviewToFront:yourButton];
I don't know if you were used xib...
If you are using xib in your project, giving a background image for your button will more easy.
Place a button anywhere you want. Then go to attributes inspector on the right hand side. There you can find a field for changing your background image. Just give the name of your image.
Hope it will helpful for you

How to set the background image of the main view in XCode storyboard editor?

I am trying to set a background image for my main superview in the story board editor without creating another view(just for a background image). I can change the class of my main view to UIImageView, but the editor will not show me the option to specify a background image. How can I make this work?
It is possible, but you won't get visual feedback from the storyboard. Under the Identity inspector (cmd+option+3), there is a pane for setting user-defined runtime attributes, and setting the backgroundColor to a [UIColor colorWithPatternImage:] should work just fine. I would however, for clarity, keep that sort of stuff in the viewDidLoad-method

Why are two different UIToolbars, defaulting to different styles?

Consider the following two toolbars that are in the same project of mine:
Notice that these toolbars look different? The problem is that they were both created by dragging and dropping them into IB, and I didn't change any of there associated properties. All that I did change was adding the flex controller, and change the text on the initial UIButtonBarItem. Other than that, these Toolbars have not been modified and, furthermore, I've verified that their properties are exactly the same in the Attribute inspector.
How or why are they different? Furthermore, how can I get the first, bluish UIToolbar to look like the grey one since the available Black Opaque and Black Translucent styles look nothing like the grey one?
Am I missing something? This doesn't make any since.
I've found why this is happening but I'm a bit clueless on how to change this. See this, new question regarding a fix for this issue.
These Toolbars are changed due to internal Xib settings that are specified when the Xib is created. In the first example, when I created the UIViewController I must have unchecked the Target for iPad check box, even this is for an iPad project.
This changed the default size of the initial UIView that was in the Nib. I always cut off the statusbar and set the view to be freeform in sizing as soon as I create a UIView within a Xib file, so I can never tell by looking at my views whether they were targeted for the iPad or not.
When I created the second UIViewController object, I checked the Targeted for iPad option. Now, my toolbar is styled with a grey tone.
The lesson learned is obvious-- if you want consistency in the default style of your objects that you pull from the IB Toolbox, be sure to create your UIViewControllers, specifically targeted for the iOS device. If you've made the same mistake that I have, follow the linked question above for how to revert your UIViewController and Xib file to the other style of View Controller.

Resources