Create a custom step indicator in iOS with Swift - ios

How do I create a progress indicator as shown in swift for iOS? Tried various libraries. But nothing fits exactly.The color should be in gradient and the current state must show the step number.

If you want to create any custom control element You should inherits your class from UIControl. You can read about this here:
custom knob,
custom slider.
But You will have to write too many lines of code to create customize view.
However, You can use my turnkey solutions: https://github.com/vladislovshilov/StepView
Unfortunately this library does not support touch yet.

Here is an example that uses a UIStackView, works nicely with auto layout, is animatable, and is configurable in Interface Builder.
https://gist.github.com/Dev1an/aa54ae331f4065569dc613d7f904bd54

Related

how to add checkmark in UISwitch control?

Hello everyone i am trying to add a checkmark on UISwitch control. I do not know where to start. Any help appreciated. Result should be like the image below. Actually i have already an implementation without the checkmark but i need to add the checkmark somehow.
The short answer is that you can't do it with UISwitch. Before iOS 7 you used to be able to set on/off images, but those properties are now deprecated. If yo don't like the default styling, you have a few options:
You could add a floating image on top of the UISwitch like #DonMag suggested. This is probably the easiest way to go, but might not end up with the exact visual treatment you want.
You can use use a UISegmentedControl or a UIButton. Both of those classes have ways to set custom images for different states. UIButton is likely simpler to customize than UISegmentedControl.
You can build your own UIControl or use an open source custom control (i.e. from Cocoapods, or other source). Going open source will be easier than building your own.

Custom slider iOS objective-c (Increase Height of Horizontal Slider and Add Image on Thumb)

I want to implement custom slider
i tried a lot and get this https://github.com/jane/JaneSliderControl but is not in objective-c.Can anyone help for creating custom slider
If you want to create your own custom UI, why don't you try a very handy tools like PaintCode.
With PaintCode, you can create any custom UIs without any hurdles. After creating custom UIs in PaintCode, you can generate code in Objective-C, Swift as per your requirement and embed in your project.
Here are some of the tutorials to start with PaintCode.
https://www.raywenderlich.com/92972/paintcode-tutorial-for-developers-getting-started
https://www.raywenderlich.com/97941/paintcode-swift-tutorial-part-2-custom-progress-bar
https://www.youtube.com/watch?v=4jovZyBMdrQ (sample slider using paintcode)
https://www.youtube.com/watch?v=yweBm-UpId4

iOS: Small thumb in the native UISwitch

I'm using UISwitch in my UIViewController but I don't know how can I decrease the size of its thumb. I searched about it but I only find some libraries offering a switch with a big thumb. There is no attribute in the storyboard or the code that can help on doing this. So how can I have a small thumb of the native iOS UISwitch?
You cannot change the thumb image of a UISwitch.
Check the UISwitch documentation to see what properties are configurable.
If you want a switch with a different style, you can create your own custom UIControl subclass that behaves however you wish.
From a design perspective, there are only a small number of cases where it would be beneficial to have a custom switch. The UISwitch thumb image is relatively large to create the affordance that it can be "flipped".
The default UISwitch also contains some accessibility features that you will lose if you create a custom switch.
I found a great pod that solves this, and many other problems on GitHub.
This will allow you to create switches with custom sizes, shapes, and gives you a lot more power over customization.
I just installed the class into my project, rather than using pod install, as it is only a single file class, and as of this posting was not updated to Swift 4.2.
In order to use it with Storyboards, I added a UIView of the shape and size I wanted the switch, and then added the my custom switch to the UIView.
Link to the GitHub source below. Note this is not my repo, it was just something I came across.
https://github.com/bvogelzang/SevenSwitch

iOS add view to Button in IB

I am trying to add a view on a UIButton inside IB. The only problem it doesn't allow me to put in inside the button only on top?
Is this not possible through IB or am I doing it wrong?
It's not possible in Interface Builder. You have to add it in code.
You should not do this:
Do Not Customize Controls by Embedding Subviews
Although it is technically possible to add subviews to the standard system controls—objects that inherit from UIControl—you should never customize them in this way. Controls that support customizations do so through explicit and well-documented interfaces in the control class itself. For example, the UIButton class contains methods for setting the title and background images for the button. Using the defined customization points means that your code will always work correctly. Circumventing these methods, by embedding a custom image view or label inside the button, might cause your application to behave incorrectly now or at some point in the future if the button’s implementation changes.
https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW26
If you need to add a UIView on your UIButton you can achieve it in 2 different ways
The easy way is to follow Cyrille answer: you can do it programmatically because IB doesn't allow you to modify a UIBUtton adding a view on it
The hard way is to create your custom button (let me call it "MYCustomButton"), that extends a UIButton, and use it in your application. With this way when you need to modify the buttons in your interface, you can achieve it modifying the XIB of the "MYCustomButton".

Xcode custom control via storyboard

I want to use a custom control in my project, specifically a horizontal picker view I found on cocoacontrols.com (http://cocoacontrols.com/platforms/ios/controls/cppickerview). I've been able to include it into my project, load data and it works very nicely.
The pickerView is setted up programatically on viewDidLoad but I'd really like to be able to use it via storyboards because I'm a using static tableView. I tried to add a UIView, set the class to the PickerView class and then set up the outlet. I builds without errors or warnings but the picker view does not appear. It only shows a white rectangle.
Anyone with experience in this? Is it possible at all or should I keep it programatically?
Thanks in advance!
Well, that's normal. CPPickerView does not seem to implement initWithCoder:... I only see an initWithFrame: in the source code, which obviously means you can only instantiate that custom UIView from code. Or you can change CPPickerView's implementation to support what you want. It's open source.

Resources