Program UIButton on swift - ios

i have created a button on main.storyboard and i can add IBAction too. But, my aim is to make a sticky button(after you clicked once it is stayed pressed until you click it again) can somebody suggest please.

Set Image in selected state of uiButton,
means you need two image one for unselected and another for selected

Related

UIButton not showing any effect when tapped?

I am using Xcode 9.4.1 and I have added a UIButton in storyboard in a new project. Have changed the button to custom and have set constraints.
My problem is there is no change in button appearance when it is tapped. there has always been a default change in uibuttons appearance when it is tapped in earlier projects.
Is it only with me or its a general thing with new xcode?
You can try setting UIButton's selected state properties.
just check state of UIButton in Attributes Inspector set it enable then check type it should be system and not showing then once click on drawing = Show touch bar on Highlight then run your project and see when click is there any effect or not. Hope this is work fine for you.

how to create my own radio buttons

I am new to Swift and Xcode so I need help with what I am doing. And what I am doing is this.
I have three buttons one of them starts out checked. and what I want it to do is when I click on another button it checks it and unchecked the previous. I want my own radio buttons
For Radio Buttons there is nothing that comes built in.
You can use SSRadioButtonsController
You can create a controller object and add buttons array to it like
var radioButtonController = SSRadioButtonsController()
radioButtonController.setButtonsArray([button1!,button2!,button3!])
You can also use something like this tutorial.
The standard Apple class that is designed to work with radio button groups is NSMatrix. Specifically you'd create an NSMatrix with mode "NSRadioModeMatrix". NSMatrix takes an NSCell for its list of items. So you can use any built-in NSCell subclass (like NSButton) or anything else custom you would like.
You can manage manually by setBackgroundImage and setImage property. at initial time set rounded image as setBackgroundImage for all three button. At button click event set "bulletin" image by setImage property for selected button and set nil for all other button setImage property.

UIButton and UIControlStateHighlighted issues when starting app

for my UIButton I have its Default State Config set to buttonLong_beige.png and Highlighted State Config set to buttonLong_beige_pressed.png everything works as it should when the button is pressed, I press the button and the image changes from buttonLong_beige.png to buttonLong_beige_pressed.png each time i press it but the issue is when the app starts... before the button is even selected, it is already highlighted even though I never touched it yet... but once I press the button it returns to buttonLong_beige.png and then changes back and forth each time its pressed..... I have no code to display since this is all done in the storyboard, im very confused...
Check this in the "atribute inspector"
Its looks thats your button starts highligted, so un-check that.

iOS: How to disable Fading in and out effect of UIButton

First of all, sorry for the title and asking this incredibly question but I simply couldn't figure it out. Also, since it is not related to code, I don't have code to show
I am working on an app and using iOS7 and I created a button from IB, set its background image to an image I designed. Connected it with header and set its touch up inside action as an IBAction
Yet, here is my problem. Whenever I click on the button, as an effect the image fades half transparent. I do not want this default attribute. I checked all the states on IB (highlighted, disabled, selected) and couldn't figure it out.
If I create the same button programmatically, only the text color changes, however when I set the background image, image fades (perhaps to indicate the button being pressed). How can I remove this effect?
A bit late but I believe this would solve the problem
in the xib file, set the button's type to Custom.
My button was set to system and when pressed on, it shows transparency and has a little fade in effect. Once I changed it to custom this effect is gone.
This cannot be changed once button is created. only in xib or when the button is first created.
have you tried this one yourButton.adjustsImageWhenHighlighted = NO?
If you set same background-image/background-color for every buttons states in IB (highlight, disable, selected) you will not get any fading in UIBUtton when you press it. You can set text color for every states also. If needed you can set different colors for every state and check the press action.
Hope the answered you expect. Thanks
Storyboard Solution
1:set button type to custom
2:uncheck "Highlighted adjusts Image"
If you want fading in & out effect your UIButton Type Should be a system, not custom.

ios navigation buttons

I'm doing a custom nav in ios for the first time. I have six buttons laid out in a row. When I tap the button, I want the image to change. However, the button is not togglable. The only way a button can be unselected is if another button is touched. Only one button can be active at any given time.
My idea:
use UIButtons
change UIButton image on touch
keep track of the active button inside the navigation class
when an inactive button is touched, make the currently active button inactive and turn the touched button to active
I want the end product to work like a custom TabBarController, but without switching layouts. I just want to edit the content in the current ViewController.
Is there a better way to do this?
You could just use the UISegmentedControl, which has that functionality already. If you need to significantly customise the look and feel though, your UIButton solution sounds fine.
I setup the UIButtons in the Interface Builder like so:
Default with unselected background image
Disabled with selected background image
On touch, a button is self.enabled = NO which makes the UIButtons look change. However, the button goes dim, so I also implemented self. adjustsImageWhenDisabled = NO.
This way a button can't be re-selected once it's "active".

Resources