How to make a circle on the LaunchScreen? - ios

I made a Cocoa Touch Class called BlackCircle, a UILabel subview which called the drawRect() method to make a black circular label. I dragged a UILabel onto the LaunchScreen.xib file, and when I assigned the Cocoa Touch Class File as the class of the UILabel, I got an error-
"Launch Screen may not use instances of BlackCircle".
It works fine on the main.storyboard file, but it doesn't work on the LaunchScreen.xib file. How can I fix this? Thanks!

LaunchScreen will not load your custom instances. Remember the app hasn't launched yet. Thus you cannot have custom instances.
You are only allowed to use basic UIKit classes like UIView, UIImageView, UILabel, etc.
Your best bet would be to make an image resource for the black circular label and import it to the LaunchScreen.xib

Yes there is a way!
You can add an image view and use SF image like "circle.fill" (just enter the name in the topmost text field) and use tint color to style it in your way.

Related

Create a custom UIButton with text and icon

I would like to create a custom UIButton looking like this:
The idea is simple, I want the titleLabel to start 24px from the leading, and stop 12px or more to the icon image (which is the square view at the right of the button). It can contain up to 2 lines.
The thing is that I have no idea where I should put this code in a class inheriting from UIButton.
What should go into draw(_ rect: CGRect)?
Also, should I use the titleLabel and titleEdgeInsets UIButton properties and the imageView/imageEdgeInsets as well, or instead use custom properties for this?
You just want these buttons to work, be tapped, and react somehow?
These buttons are custom buttons, and you may a create a Cocoa Touch Class file for them; name it and let it inherit from and be a subclass of UIButton.
Then connect that file to your buttons in the storyboard.
But first, you need to set/attach the newly created file to your buttons. Click on the button, In the identity inspector of your storyboard, with your button selected go to the Class field and type the name of your new file and don't forget to tap 'return' to save your changes.
Now, your buttons are attached to that custom UIButton class.
From now, you can attach all your icon images and many more as outlets to your custom UIButton Class you just created.
Most importantly, now these buttons can be used on their own; they can be outlets or trigger action methods. And to make it look just as you except, you just have to initialize your buttons, i.e. provide an icon image, text, etc.
Is what I wrote clear?
If not, I am glad to help you.

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

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

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

Add icon to SBSearchTableViewCell

I am trying to add an icon to a SBSearchTableViewCell.
I was adding a subview on top of the cell but that still left a border, and the text was underneath the icon.
http://i.imgur.com/tGqWaEa.png
I tried hooking into -[SBSearchModel _imageForDomain:andDisplayID:] but the domain is 0 and the displayID is (null).
Code: http://pastebin.ca/2460380
Resources:
http://theiostream.tumblr.com/post/54339870761/hacking-the-ios-spotlight-v2
https://github.com/theiostream/SearchLoader
Did you try to set image using -(void)setTitleImage:(id)image animated:(BOOL)animated; method (I'm not sure what it does, but that is the only method to set image in the cell you are using...)? And, How about just creating your own labels, and place them on the right places? That should not be that hard, I think. Good Luck!
EDIT
Sorry it seems like the method I mentioned is available only on iOS 7 and higher. I suggest you to use you own UILabels and UIImageView with imitation to the original.
ANOTHER EDIT
It looks like the SBSearchTableViewCell is the subclass of the UITableViewCell, so why don't you use the it's imageView property to set the image (or, icon) to the cell?
You can move the border over by setting cell.sectionHeaderWidth. Then you can add a subview like you already have done.

iOS modify the layer of a UIElements that are created with IB

In my app, I would like to create a custom UIElement, in my case a UITextView with rounded corners and border color and everything. however I can only do it if I create the UITextView from code and add it to a view with the addSubView method.
That's not too elegant, plus it fails during the unit tests as well.
Is there a way how I can create my UITextView with using Interface Bulder and still being able to modify its layer property?
Any help is very much appreciated.
If you create an IBOutlet by ctrl-dragging from the nib or storyboard to your .h file, you can access your graphical element as usual with something like myTextView.layer.cornerRadius = 5.0;.

Resources