Draggable background boxes as sliders in Swift - ios

I am currently using XCode 8 and Swift 3 and I have been searching and haven't been able to find a way of being able to complete what I want to do - basically, I want to be able to have a progression box behind text which I am able to drag from the left to the right to be able to have a 0-100 slider. I have created a mock-up to be able to attempt to describe what I am attempting to achieve, the progression bars in the background should be able to be slideable which will update the progression number once it has let go.
Any help would be appreciated on this as I have been stumped for awhile now.
Here is the mock-up:

One method: use a UISlider "under" the labels. Might be able to get away with tint colors - if not, then transparent images for thumb and max track image, and just-a-little translucent image for min track image.

Related

SWIFT - pulsating glowed circle around label and animated line

I'm trying to recreate this effect I see in Tesla app.
We basically have some labels with a glowing circular shape around and an animated path going from one label to the other.
can someone try do drive me in the right direction ? I can find example for swift ui but not so much for swift

How to detect the color of an UIImage in iOS

I have a view like this :
The left back button & the right button is basically two white image (set in UIButton) with a particular opacity. Now it's look more or less visible on this background cover photo.
But if I change the background cover photo with something else, where the opacity & color of that cover image is closer to the two button's image, then it's difficult to see those two button.
Like this:
So I just wondering, Is there any way, so that I can detect the color of my cover image and I can change those two buttons image or color according to it?
Any kind of reference or guidance would be very much appreciable.
I think you can use this function to determinate how light/dark is the background. Calculate an average of several pixel under your button.
Have fun! :D

Custom shaped buttons objective-c

I'm building app for kids with lots of interactive image objects (click on pic & get result)
For example: I have cat on my screen and with click on it I need to produce sound.
After having read lots of info I got the idea that it's almost impossible to transform certain parts of image to clickable objects.
While there are lots of games on the app store which contains lots of custom shaped clickable objects. How did they manage to do this?
What I need read to get the answer? Thank you in advance.
UPDATE: I can have my clipart images as vector-graphic, e.g. .svg file. Will it make the situation simpler?
Implement each image as a UIButton and set the background of each button as the image desired. (setBackgroundImage)
Links:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/
Using images is one option, but if you want taps within a certain non rectangular shape, check out OBShapedButton
If you really want super accurate touches, you could construct a bezierpath in the shape of the image then use
[UIBezierPath containtsPoint:]
https://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/instm/UIBezierPath/containsPoint%3a
You could also possibly get the pixel colour underneath the touch, but that wouldn't give much room for error if the user tapped near the edge:
https://stackoverflow.com/a/7101544/78496

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

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.

masking a background colour over the transparent region of a UIImage in objective C

Im a little bit lost on how to go about this, im really looking for the theory behind it im not 100% sure if the title is correct or not.
Im currently working on a iOS app and im a little stuck with the progress indicator thats been designed ive attached a image of it below
as you can see when the user progresses through the stages of the challenge the background of this image fills up with white so if they are in stage 1 of a 5 stage challenge its filled 20% stage 2 40% etc.
the issue I have is im not 100% sure how to go about this, if I was doing this in HTML i would create the image with the green background and leave the area for the rabbit and shape transparent and then create a div behind it that would change its height.
should I be applying the same principle to iOS development or should I be building it in a more programatic and efficient way.
thanks all for your help
The solution you are talking about sounds fine. Many programmatic solutions would involve masking and would probably be less performant (masking is actually quite expensive), other programatic solutions involve stroking different vector paths but that would get complicated if you want to cut them all of a the same line.
So, translating your idea into views. Create a container UIView with a light green background, and add to it a white UIView and an UIImageView (in that order to get the image on top). The image view would have the green image with transparency set as its image. The white view would start of being positioned below the light green view (have a frame with a higher y value) and as the stages progress you simply shift the white view upward by modifying it's center or frame properties. (note that y increases downwards).
This may be a childish way
Make an UIImageView and add that in your view where you place your rabbit view.
Make the width and x axis value as same of your rabbit view and change the height and y-axis value as the stages completes.
Add the rabbit view above your imageview.
In this way you can have not only color of your progress you can even assign a image in future to show the progress of the different changes.
-(void)completedStage:(int)stage
{
CGRect frame=rabbitimage.frame;
bgimageview.frame= CGRectMake(rect.orgin.x,rect.frame.orgin.y+rect.frame.size.height-stage*0.2,rect.frame.size.width,rect.frame.size.height-0*2)
}
Hope this helps !!!

Resources