UISlider - draw line / image to the track (bar) - ios

I have UISlider with min and max track colors. I want to draw vertical line (or image) in the middle of the slider track. This line must be there the whole time, only color on top of it will be different (min / max track color).
If I put UIImage on the Slider background, tracks covers it. If I set clear color for tracks, I can see line, but no colors from tracks (obviously). Is there any simple way, how to do this, or I have to override drawRect method for Slider ?
Something like on the slider in image

Note that the sort of "ultimate" solution to this type of project is...
http://www.paintcodeapp.com
As #BradAllred pointed out, the fundamental problem here is: you are trying to avoid drawRect.
Realistically, you can only achieve your goal here by subclassing UIControl or slider.
As others have mentioned fortunately there are many great tutorials, etc, on doing this -- and it's not hard.
Once again paintcodeapp.com is kind of an "incredible secret" to making iOS apps, enjoy.

add an UIView that is 1 pixel wide and has the height of the Slider and put it over the slider.

Create a CALayer, draw it, (even add an image to it), then add that layer as a sublayer to the Slider's layer.contents.

Related

How do I create a segmented circular progress bar in Swift?

I wanted to create a progress bar as shown in the image:
I used the code mentioned in this blog
but I am unable to add separators and reduce the space between them.
I have managed to do like this through storyboard:
How can I change the code or is there any easier way to create?
You didn't specify what sort of animation you want on your progress indicator, but certainly achieving the drawing you've shown in your first screenshot shouldn't be any problem; I was able to throw this together in a couple of minutes:
Each thing in that drawing (other than the face) is a CAShapeLayer: the dark background circle a shape layer, the animated green circle in front of it is a shape layer, and each of the eight little lines that indicate the segments is a shape layer. So I have ten shape layers in total. They are added in that order, so that the little lines appear in front of everything else.
If the goal is to "fill" each segment in discrete steps, rather than a smooth animation through all values, that's a trivial modification of what I've already described.

Inner shadow on UICollectionViewCell

I have created a nice looking collection view with image cells inside. I wanted the cells to be round so I made maskToBounds equal to true and set the corner radius to half of the image's width. This all works fine but now I want to add shadow effects to the cells and there are 2 problems:
I want to have an outer shadow on some of the cells (which is currently being cropped off because I set masktoBounds to true...
I want t have an inner shadow effect on some other cells (they are supposed to look less highlighted), but I don't even know how to make an inner shadow...
Any help desperately appreciated,
I work with C# in Xamarin.iOS by the way, but I will also understand any other language.
Cheers!
Take a look to the UIView.Layer.ShadowX and play with the values of it I recommend to use an image instead to simulate the effect because the Layer effects will kill your device processor
Take a look at the XamSvg component. You create 2 svg with a gradient to mimics an inset and an outset. As it is an svg, it is stretchable and could be set as your cell's background to simulate your shadow.

Specific position of WKInterfaceImage alignment (Watch OS 2)

I just bought the Apple Watch and I want to create a super simple game for it.
It is simple enough to only use monochrome color scheme, but advanced enough to have an object moving in real-time.
I am trying to figure out how to position an object on my Apple Watch with Watch OS 2.
I want to place my object somewhere on the screen (anywhere I'd like to) but there are absolutely
no way to do that, I think.
But, in the following library: https://github.com/shu223/watchOS-2-Sampler
the developer can actually animate the alignment of the image so I guess
that itself suggests it should be possible to somehow specify a point of where to position an object.
And the animation is pretty smooth as well.
I have tried to generate frames on-the-fly CGContext which uses Quartz 2D, but it's way too slow and the app on my Apple Watch just crashes.
I don't necessarily think that the watch itself is too weak, but some clever programming should solve my problem, but I just cant figure out how to do it.
As you already said there is no way to directly position an WKInterfaceObject on your watch. You can change the alignment of an object but that leaves exactly 3 positions: left, center and right. Probably not enough for your game.
What you could do: You can set a background image on a WKInterfaceGroup. So you could draw your game objects into an UIImage and set that as background image of that group. That background images can also be animated. So maybe you can draw the movement of your game object into several UIImages and then set those as animated background image.
One way that I have found to have a little more control over where a WKInterfaceObject is on the screen is to add it to a parent WKInterfaceGroup, and center your item (vertically and/or horizontally depending on how you want to move it). Then you can tweak the group's relative height / width (setRelativeHeight and setRelativeWidth) and it's alignment (setVerticalAlignment and setHorizontalAlignment) to get your item positioned where you want.
This doesn't give you the ability to tweak frames or give the item a particular coordinate, but it does give you the ability to programmatically move a WKInterfaceObject anywhere on the screen.
For example if you want your object in the exact center of the screen vertically, you leave the group's relative height to its container as 1, with your item centered. To get the object at 40% from the top, you can change the group's relative height to 0.8 and it's alignment to .Top. If you want it 60% from the top, the relative height would still be 0.8, but the group's vertical alignment should be .Bottom etc.
I know this is kind of a confusing way to have to accomplish this, but this worked for me in getting items positioned exactly how I wanted.

iOS Circular Slider

I want to create a circular slider like below.
But i want two functionalities in addition.
1) I want to start the slider from any point,but in fig. it starts from 0.
2) I want to include multiple sliders in a single circular black plot.
I'm sharing the link of this project:
https://www.cocoacontrols.com/controls/circularsliderdemo
Can anyone help me to do these functionalities.
Thanks in advance.
Take a look at CAShapeLayer. You could create a path that is a full circle, and use the strokeStart and strokeEnd properties to only draw part of the circle. You could use core animation to animate between the beginning and the end.
There is an open source custom gesture recognizer on Github that is a one finger gesture recognizer. That would be a good start for detecting and responding to the twirl gesture that such a control would need. EDIT: It's called KTOneFingerRotationGestureRecognizer (link)
Those are some ideas to help get you started.
I have a project on github called iOS-CAAnimation-group-demo That includes a "clock wipe" animation. The clock wipe works by setting up a shape layer as the mask layer for an image view, installing a full-circle arc that's wide enough to completely fill a rectangular area, and then animate the strokeEnd property of the shape layer to reveal/hide the image view. The clock wipe is much more complex than what you need, but it would give you the seed of what you want. You'd use a shape layer with a much thinner line width, and you would use it as a content layer, not as a mask.

UISlider Custom Thumb Image Resizing Issue

I want to get directions for following two issues related to UISlider control customization.
Issues#1:
I just updated the UISlideThumbImage as seen in following screenshot. As thumb image is in retina display, so its large image; My question is how we can resize the thumb image? I don't want to resize thumb image PNG. If i will do that then on retina display screens, it will seems blur.
Issue#2:
Default clickable area of thumb image of slider is 23x23. How we can increase that area? So that we can adjust it according to the size of thumb image. Currently, if i will move finger in 23x23 bounds, it will start sliding but if out side of that bound, it will not move but i also want to move the thumb if i will slide on any place of the thumb image.
Your important suggestions will be move helpful in this regards. Is there any third party library present which will do it more efficiently regardless of doing it ourself and spend more time over it?
From my experience with customising UISlider, It's better just not using the default one.
There is a open source Range Slider:
https://github.com/muZZkat/NMRangeSlider
And notice there is a option to remove the lower thumb so you acutely have a regular customising UISlider
"(New) Disable lower handle so it behaves like a regular UISlider but still use other features."

Resources