Custom UISlider with pips ios - ios

Wondering if the above can be created using UISlider? If not, what other ways can this be accomplished?

You can set components of a UISlider, such as the currentThumbImage ( see: "Appearance of Sliders"1).
However, it is almost certainly easier to just re-implement a slider for this much customization. Simply use background UIImageView with the scale image, and then add a separate UIView (or UIImageView) for the arrow. Finally, attach a UIPanGestureRecognizer to the arrow view to allow a user translate the view vertically.

You can change a lot in the appearance of a UISlider like setting the thumb to a red arrow. You can also replace the background image with the inches ruler and with different rulers for the different device types and display sizes.
The one thing that I don't see is that you turn the slider to work vertically. I know them only working left to right.
If I'm right, your only chance is to have a ruler as background image and a view that contains the arrow and a label with the actual value. That whole view can be pawned and tapped using Gesture Listener.

Related

UIButton with background image and title using auto layout

I currently face a problem when using UIButton. I have the background image designed by others like this:
background image
and I need to place the title for the button right after the white vertical bar in the background image. I tried to set left edge for the content but since I used auto layout, the frame will be different with different screen size(3.5", 4.7"...).
Is there a way to put text in the position related to background I want with auto layout.
Thanks
I personally would split the left side of the background image from the right side. This way you can have two UIButtons next to each other with horizontal space constraint of 0. The right side of the button will have to be placed inside a UIImageView so you can set the image as a property of the view rather that the button's background. You don't have to do this of course, but I prefer this solution as it is easier to manage across different screen sizes.
Here is a visual representation of what I explained above:
Separated Views for Single UIButton
You will then need to route the touch events of both buttons to run the same method or function, just so that both the right side and the left are clickable.
Note: I'm not sure exactly what you had in mind for the highlighting of the button, but this will have to be tested and adapted to get the desired effect.

annotate buttons onto uiimageview (like mkmapview without MapKit)

I have a UIImageView set on top of a scrollView. The image is a map, and I need to annotate buttons across the map to corresponding locations (very specific to the region). The buttons are visible, and they pan and scale accordingly when scrolled/zoomed, this works great. The issue is when the buttons are rendered on different screen sizes, the buttons are placed in different spots since auto-layout puts them the same distance from the edge of the screen, but the image has a different bounds property and is bigger/smaller depending on the device.
I've considered creating an MKMapView with a custom overlay of this image, but I was hoping to keep it super light-weight and avoid MapKit all together.
Any suggestions? Clarifications are fully encouraged :)
You should add buttons as subviews on imageview so that buttons transform in the same way as imageview does.

iOS segmented control with a little triangle on top

How can I draw a little triangle above the selected item in a UISegmentedControl? Does anyone know an open-source than extends it?
(if not - pointers of how to do it)
Design should look like (this is in the bottom of the screen)
I don't believe there's a native way to do that. You can either find a library that allows for it, but you can do it yourself fairly easily, which I recommend.
I can think of a few out of the box ways to approach it, here at the two I think worth mentioning off the bat:
1) Use UISegmentedControl with images. Make the segmented controller have a height that includes the triangle, and have an image for selected and normal states that shows what you want. The Normal states would have a rectangle of transparency on top, as wide as the entire image and as tall as the triangle. The selected image would include the triangle. Both images should end up the same width and height.
2) Subclass UISegmentedControl and do some custom drawing in drawRect:. You could draw the triangle outside (above) the bounds of the segmented controller, make sure to set the segmented controller's clipToBounds property to NO, as well as its layer's masksToBounds property.
If you'd like more help, or some other suggestions, just ask.

Fade UIImageView as it approaches the edges of a UIScrollView

I have a UIScrollView over an image at the bottom of my app that acts as a dock with icons that can be scrolled through horizontally. Instead of the harsh edges of the UIScrollView, I would like the icons to fade out for a more aesthetically pleasing look. Being new to iOS development, I don't know if either of these would be valid options:
Create a faded image to use as an overlay on the scrollview so the
icons only appear through the visible portion.
Actually change the
alpha of the images based on their distance from the center (or from
each edge).
I suspect the first idea would be the most simple, but I'd like to throw this out there for any other ideas.
Note: I did see this tutorial, however that technique assumes that the background is a solid color. If I were to do it programatically, I would probably need to fade the individual images.
You can definitely implement something along the lines of #2. It'd be something similar to what the tutorial describes. The alpha transition however won't be as smooth as using the gradient layer mentioned in the tutorial or using an image since the entire icon would have the same alpha. How much discernible the difference is depends on the size of your icons. Smaller icons, very few will be able to tell the difference. Larger icons the difference would be quite clear.
You'd have to implement the
(void)scrollViewDidScroll:(UIScrollView *)scrollView
method in your scroll view's delegate class. This method will get called every time the scroll view changes the location of its content. In this method you can call its subviews and adjust their alphas as required. To optimize it a bit instead of calling the alpha adjustments on all the elements you can just update the subviews which are still partially/completely visible.
EDIT: to figure out which views to adjust you'll use the contentOffset property of the scrollView that gets passed as a parameter in the above method.

slider control similar to ipad default calendar app

I would like to know how to implement the slider similar to the one in the Ipad default calendar application. I have attached the image below
If you see at the bottom, it acts like a slider which allows us to select any month either by just pressing it or sliding to it.
It would be great if anyone could tell me the name of that control. I tried using UISlider but I see that it allows only 3 options:
setThumbImage
setMinimumTrackImage
setMaximumTrackImage
If that control is indeed a slider control, could anyone tell me how I would be able to insert multiple images/ text
Thanks
It may be more complex than you'd like, but you could make your own:
Make a background that has UILabels for the dates
Make a selection box
In the UIViewController you could put something such as:
touchesMoved -
Make the selection box's x value equal to the touch
touchesEnded -
Make the selection box's x value equal to the touch's last x value
The touches moved would allow dragging of the selection box, and the touchesEnded would allow tap selection.
Then you would simply animate the selection box to the x value.
(This is an extremely simplified version, but you could do this pretty easily.)
This can be achieved by using UIScrollView. Add UIButtons programmatically having background images and text as well on them as per your requirement.
You can refer tutorial1 tutorial2 in which on screen only 1 page(Image) is displayed. You need to do some calculation for applying same logic to fit your requirement. i.e. Your scrollview will be smaller(in height) and bigger(in width) as displayed in image, you will be adding UIButtons in spite of images and most important at a time displaying more than 1 item but it won't be difficult. The Main part is only programmatically scrolling.

Resources