Customized UISlider with one more view - ios

I need to create a subclass of UISlider in swift so that it has 3 bar views & 1 thumb image. Currently iOS Provides only 2 bar views & 1 thumb image.
The two bar views are minimumTrackImage & maximumTrackImage.
I need one more bar view on right hand side which is permissible limit of UISlider. i.e if slider has current value 50 max allowed value value is 100. I can able to set Permissible limit to 80 and slider will look like as below.
Could anyone please help...

Here is an example I quickly put together that hopefully shows what you need (see github-link below)....
Link to the example "permissibleLimitSlider" on GitHub
(The solution is done with Swift-3.1, Xcode-8.3.3 and iOS-Simulator-10.0)
The trick was:
A) to create a new maximumTrackImage (called "slider-track" in my example). I created that image in photoshop (but you can use a different graphics-program).
B) to add an IBAction (with Event "ValueChanged") from your Storyboard-Slider into the MyViewController. And in this method you simply observe the sender.value and limit it to 0.8
That's how it looks like in my github example:
Feel free to change colors by changing the Asses-images in the project!
Hope this static limit (of 0.8) is what you need. If you need a dynamic limit (settable in code), I suggest you provide something like 10 images, make the Slider a "discrete slider" and set your maximumTrackImage to one or the other image whenever you need to...
More examples on how to make your slider a discrete-slider can be found here
A very good tutorial on how to make custom-sliders can be found here

Related

How do i place a button in the background?

I have quite a few labels and buttons on my view controller and I have an image and I have set it to the back in the layers part on the left. How ever when I make it bigger it seems to go to the front and block the images. I have tried multiple codes from other people who have the same problem, but it still doesn't work. I am using Xcode 8, Swift, iOS.
In interface builder you can change the order of what is in front or behind by changing the order of the views as they appear in the Document Outline...
The higher up the list they appear, the further towards the back they are.

Add text above image in UIButton

So I have UIButton's all over various VC's and Scenes on my game. Some with images others just plain text. So I want to combine both. I know I can do both but the button is then in the background. Is there anyway I can make sure that the text is above said image and the whole thing is clickable?
Everything i'm doing is via the storyboard and not programmatically but i'm fine with doing programmatic. I'm looking at the API as we speak and it seems that I'll have to deal with edges? Never done that before so, just need some guidance :/
The guide I looked at before on stackoverflow was from 5-7 years ago and applies which is fine but setting the edges isn't as self explanatory as it might seem :/
Here's what I have:
dosplayas.titleEdgeInsets = UIEdgeInsetsMake(((dosplayas.frame.size.height)*(-(2))), 0, 0, 0)
I also tried positive two and I tried it as the first of 4 parameters because the first one is the top according to the API
When setting image, just set background image rather than regular image. it'll allow text on top
Then change text to attributed rather than plain
Then..here's a screenshot:
-click the 3 dots
-change the lining to like 7-20 depending on the size of your text

Place image on top of all "layers" on iOS screen

What are the constraints/alternatives to place an image that stays on top of all iOS "layers" and windows. Think of it as a lock screen but that still allows you to interact with you phone, meaning browse, answer calls, etc. The image will be displayed in a transparent way (say 40%) and will be launched by an application.
Not really sure what you are asking for but if you are looking for a way to add some code once and it shows everywhere on each of your ViewController then there really is no way to do that.
What you can do is
Use UIToolBar
add buttons to that tool bar
Add that tool bar to each ViewController in storyboard (where you need them)
Create a global function / method that you can call in from any ViewController that has the button actions in it. That way you edit the code once in one place and use it every where.
If you don't like UIToolBar then
you can add your own UIImageView and add a transparent background to it
Add your buttons on the UIImageView. (You will have to add constraints)
then show that on every ViewController
If all this seems to much work then you can use existing controls HERE and see which one fits your needs.
This maybe a good one - FCVerticalMenu

UIPageControl select dot and go to that page

I have aUIViewController, which has inside a UIView in which I add a UIPageViewController with the UIViewController as the delegate. The thing is that the UIPageControl of the UIPageViewController is not working as I had expected regarding the dots selection.
I was expecting that if I selected the dot 4, it would take me to the dot 4, yet, It doesn't work like that. It always goes to the following page if I select the right half of the UIPageControl (inside the blue square of the image), and goes to the previous page if I select the left half of the UIPageControl (inside the red square of the image). So, If im in page 2 and select around the second dot, it goes to page 1 (instead of staying on page 2)
Moreover, If I click exactly inside one of the dots (any of the dots), the click is ignored, although im not sure how this works on device (since in the device is more difficult to click exactly inside one dot).
My questions:
1 - Is ignoring exactly inside the dots behavior normal (by exactly inside the dots, I mean not around them)?
2 - Is two halves selection of the UIPageController to move between pages behavior normal?
3 - How can I make it so that if I press the dot X, it takes me to page X (instead of the current two halves behavior)?
Note: I prefer swift
1 - Is ignoring exactly inside the dots behavior normal (by exactly inside the dots, I mean not around them)?
I've never encountered this. I would say its not normal. Something may be overriding it.
2 - Is two halves selection of the UIPageController to move between pages behavior normal?
Yes this is the default behavior for UIPageController.
3 - How can I make it so that if I press the dot X, it takes me to page X (instead of the current two halves behavior)?
I would recommend not doing this. The reason that it isn't this way by default is the touch space is too small (when using a finger not a mouse). So it makes sense to only go forward and back. You'd have to create a custom UIControl to be able to do this if you really need to for some reason.
I would suggest you to use external library for that, as this problem was more or less solved. It is quite complicated to do by subclassing native page control but you can probably find implementation somewhere.
This library does exactly what you want (jump to page) :
https://github.com/Spaceman-Labs/SMPageControl
In the documentation, look for section "Direct Page Selection"
Hope it helps!
Edit: Few more libraries to look into:
https://github.com/TanguyAladenise/TAPageControl
https://github.com/nicklockwood/FXPageControl (very extensive, probably too much)

What is this iOS Contol and How To Implement it?

I'm confused about:
1) What type of control is the one shown in the picture above. I tried slider, it's not giving that same visual effect
2) How can I implement such a control exactly as seen on the image.
It could be anything, but if i wanted to do it i would do it as a normal custom UIView, that has 3 UIButtons
This control will have a function like, setLevel:1,2,or 3
depending on the integer it will change the image of the UIButton accordingly
1) If you just want those 3 points(Low, High, Medium) you can do as #Omar suggested in his answer.
2) But if you want all intermediate points and the middle (blue) dot as a handle, you can use UISlider and change its minimumValue, maximumValue and thumb images.. See this tutorial
You can have two images one for selected and other for unselected and when any of the button is pressed change the image of button to selected image in button action and other two button will have unselected image.At a time only one button will be in selected state.
Now predefined iOS control have this presentation.
May be you can find in cocoacontrols.org or binpress.com to see if you can download a third controls made by developers.
Also, you can create yourself the control, on the two previous website, you can surely find a lot of control which mimic the display you want. You can download the source code, reverse engineering and build your own control
At worst, build this control from scratch with a UIView (maybe a UISlider) as super class.

Resources