Hello I am a very new and inexperienced developer and I am trying to border around a button. I’m using the Storyboard and when I used ViewController.swift, I can’t make the button a weak var. It is only allowing me to edit the actions. Please help, thank you!
When I usually do this it allows me to choose if I insert "Action, Outlet or Outlet Collection."
3
Answers
Drag and release, then from the little menu that appears select
outlet
rather thanaction
. Then, to set borders do something like:Your screenshot shows "Mates Scene" but your class name is
ViewController
. It also looks like "Mates Scene" has an embed segue to aViewController
, so it looks like you might be trying to add anIBOutlet
to a child view controller from one of the parent view controller’s views (the "Home Button").If so, you can’t do that. You may have meant to add "Home Button" to the class of your "Mates" view controller instead.
In recent versions of iOS Buttons don’t have any shape by default. They are displayed as clickable text.
Make sure you are trying to connect your outlet and action from IB to the right target view controller, as suggested by Tyler.
Once you’ve got the outlet and action links working you can add code to change the appearance.
If you want to make your button a rounded rectangle, say, you can do that with code that manipulates the buttons’ layer settings (corner radius, borderWidth, borderColor, and backgroundColor are pretty common properties to edit.)
Here is code that turns a button into a rounded rectangle withe a 1-pixel blue outline and a yellow background color:
Edit:
That creates a button that looks like this:
(Note that if you use a border you may need to add some padding so that the border doesn’t "crowd" the button title as in my example.)