Difference between setBackgroundImage and setImage [duplicate] - ios

This question already has answers here:
What's the difference between setBackgroundImage:Forstate and setImage:Forstate:
(3 answers)
Closed 7 years ago.
I am trying to implement a radio button feature in my app and I am switching between images using the setBackgroundImage:forControlState method and it is working fine.
However, I can see another method setImage:forControlState and wondering when to use setImage and when to use setBackgroundImage.
Basically what is difference between these two methods in terms of functionality.

The UIButton documentation does not tell you what are the differences between these two methods.
Experimenting uncovers one interesting difference: if you change the button’s frame, background images follow the size change, while images keep their original size.
Take your pick.

So simple, if you use setImage actually you say that 'I'll use an image for whole button components.' and will not able to set title etc. If you use setBackgroundImage, you say that 'I'll use an image for just background of button components.' and able to set title etc.

Related

Swift UISlider multiple track colors [duplicate]

This question already has answers here:
UISlider - missing features - snap, tooltip and ticks
(2 answers)
iOS UISLider with gradient layer
(1 answer)
Closed 4 years ago.
I am trying to create a UISlider with a track broken up into sections. Is it possible to break up the track and have each section be a different color? Rather than just min track and max track
Is it possible to break up the track and have each section be a different color?
When you want to know what a built-in interface object will do, consult the documentation (e.g. https://developer.apple.com/documentation/uikit/uislider). You will readily learn that the built-in slider control itself can't do what you describe. But you can. For example, you could make a clear track and put the sectioned view behind it, or create your own slider control that draws the way you want it. There are lots of online explanations about how to write a customized version of a slider.

Is there a checkbox in Swift? [duplicate]

This question already has answers here:
How to create radio buttons and checkbox in swift (iOS)?
(20 answers)
Closed 5 years ago.
I'm looking for a checkbox component in Swift. UISwitch seems not so handy because there I found no way to define a label for it.
Very good I find the component the iPhone used when turning on and off the personal hotspot. But I do not know what it is?
There's no native radio button in iOS. As you can see in iOS, Apple uses UISwitch as mention by Sweeper.
Now if you aim to achieve something like this, then you can make your own control or use some 3rd party open source libraries like VKCheckBox. https://github.com/vladislav-k/VKCheckbox
I've been using this custom control and you can integrate it by either Cocoapods or by merely importing its one and only class to your project.
No, there is no checkbox control available on iOS but i was achieve it using CZPicker view, it's allows to select single and multiple options from list
Please check this URL : https://github.com/chenzeyu/CZPicker
Thanks
I have cerated checkbox with uibutton subclass -- using image and title both and adjsuting title and image with title offset and image offset.
Put a property isSelected -- On DidSet I change the image of button for select/unselect.
2.On click of button I toggle the property isSelected
On click button I triger a delegate call back for get buttons selected/unselect state in view controller.
Hope It will help.

How to make a drop down menu in Swift [duplicate]

This question already has answers here:
Making a drop down list using swift? [closed]
(5 answers)
Closed 7 years ago.
My idea is that, in order to provide to the user different options to choose it would be very interesting to include some type of IBOutlet with a drop down menu on it.
This is how it should be seen.
How is the best way to do this?
Any suggestion would be very appreciated.
Presuming that the down arrow is a button to trigger the drop-down that you've illustrated, the first suggestion that comes to mind is to create an IBAction for that button that presents a table view as a child view controller. This table view will list out the "different options".
You could always use a UIAlertController. Apple suggests that developers follow the same consistent design throughout the entire OS. As a plus, UIAlertController is pretty easy to use. (Beware though, UIAlertView is deprecated. Don't use it by mistake.)
You could also (if you have a lot of choices) use a UIPickerView.

How to fade in individual letters of text on iOS [duplicate]

This question already has answers here:
How to Make a Secret iOS App Text Animation
(4 answers)
Closed 8 years ago.
What's the best way to fade in individual letters of a UILabel over time? I'm looking to create something similar to the example below.
http://s11.postimg.org/5s16qmwn5/secret.gif
I wouldn't use UILabel to do this.
I would create a UIView with CATextLayers inside it, one text layer for each character. Then you can animate the text layers independently.
Check out apple's WWDC videos on core animation to learn how it works. It's very simple.
You may want to use NSAttributedText to create your own UITextView or UILabel that does that, basically randomly assigning UIColors with decreasing Alpha to different letters,
It will take a while to find the correct speed and rate of change. Open source it then :)

Transparent splash screen on the first (and only first) startup of an app for instructions (iOS) [duplicate]

This question already has answers here:
How to detect first time app launch on an iPhone
(17 answers)
Closed 9 years ago.
I have a simple app where the buttons are in the form of logos rather than text. Things like undo, reset, settings, etc... I'm trying to keep the interface simple, so I just want to have instructions shown on the first ever startup of the app. I've seen this done in other apps, where a transparent subview with labels is loaded, then touching the window dismisses the subview.
I currently have the launch count stored in NSUserDefaults, so I just need to figure out how to add the subview on top of the main view, which then gets dismissed on a touch. I would like to just load a png that fits the screen size in the subview.
This seems simple, but I am having trouble not overcomplicating this process.
Thanks!
check for your NSUserDefaults for the first launc and if it is then you could display your image as a modalViewController and to dismiss it on touch use touchesBegan metod to dismiss this controller.
This seems simple, but I am having trouble not overcomplicating this process.
What have you tried?
There's not much required to add a view to another view, but you don't even have to go that far. You could add your instructions view in your .xib/storyboard file and set it's hidden property to YES. Then all you need to do if the user is launching for the first time (or if they ask to see the instructions again) is flip the hidden property to NO, and then back to YES when they touch it.

Resources