How to build knob like spinner in iOS sdk? - iphone

I want to build a spinner for menu selection like the one in where to? IPhone app as shown in image below. Any hints?

Doesn't need to be very hard. The easiest is probably a UIImageView with the image of the actual spinner, and another UIImageView with the yellow selection highlight (a transparent PNG) overlaying. The rotation can then be controlled with the transform property of the first UIImageView.
This should of course be nicely encapsulated in a custom UIView subclass.

Related

How can i make a custom UIButton so that it has irregular curves like a rock,stone,tree ...etc?

I wanna to make a button so that it has the shape of a stone/ rocket (i.e. irregular shape not a rectangle, square ... etc)
, i wanna to make it also highlighted/bordered with the same shape , i tried a UIButtonTypeCustom but it did not give me what i want .. so anyone has any help or idea, don't be skimpy.
Thanks in advance.
Use UIButtonTypeCustom but also add your custom assets for the look of the button.
Typically you will set the background image of the UIButton to some image you want (your rock, rocket, etc) for each state of the button (Normal, Highlighted, Disabled…).
Simply add the images in your Xcode project, then set the background image for each state of your UIButton directly in your XIB (using the Object Inspector panel on the right), or via code using the setBackgroundImage:forState: method.

iPhone: Drawing on a UIButton

This tutorial shows how to draw on a graphics context for the view using Quartz 2D:
http://www.techotopia.com/index.php/An_iPhone_Graphics_Drawing_Tutorial_using_Quartz_2D
But I want to draw on a UIButton, not on a view. How can I do that?
Thanks
Draw on UIView . Add the view as subview to your UIButton.
A button IS a UIView. It inherits from UIControl, which inherits from UIView.
So buttons have a drawRect method.
So you can do everything described in the article you linked on a button.
However, buttons are set up to do a lot of things for you, and overriding the drawRect method could make those things not work correctly.
Buttons normally draw a title and a rounded rectangle frame. You can turn that off by setting the button's type to custom.
Custom buttons will draw an image if you install one.
Buttons normally also either draw a highlight over their image, or have a second image to use for the highlighted state. If you want to implement drawRect, you'll need to handle drawing the highlighted state yourself.
In general, you want to avoid using drawRect and use some other technique to get the content you want into your views.
What, exactly, are you trying to do?

Creating a view with notch at the edge in iPhone

Is there any possibility of creating a view like the following image? I do not want to keep a image like that I want iOS native coding functionality to achieve these notches.
Set your UIView background color to clear color from the code (or from the interface builder with alpha 0.0), add an UIImageView and use your image.

What's this UI element?

What's the UI element that is top of that number buttons to display number ? (which is in light blue color)
It looks like a UINavigationBar with a prompt. However, the location of the gloss (which differs from your typical UINavigationBar) and the centering of the numbers (not shown) makes me think it is a custom view.
If you're trying to replicate it, I'd suggest starting with a UIView. Add a UIImageView with appropriate image for the the blue background and a UILabel for the text. Or, instead of the UIImageView, you could draw the background in the UIView's drawRect: method.

Can I use DrawRect on a UIImageView loaded from a NIB?

I've created a NIB file with some button controls on it, and as a background it has an ImageView which contains a PNG file loaded from my project.
What I want to do is to draw on top of the ImageView - imagine that my UI is a clockface and I want to draw the hands of the clock on top of the background image.
Is it the correct approach to try to subclass the UIImageView and use its DrawRect as when I use the DrawRect of the default view I don't see anything on the screen?
I'm a little lost as I'm finding this particular bit of the documentation hard to follow.
Thanks.
Create a new custom UIView (e.g. named HandsView) that sits on top of your background view (by adding it as a subview of the UIImageView). In the custom view, you can use the drawRect method. Make sure, you clear the context to transparent, so that the background image can be seen below the HandsView.
If you just want to draw turning hands, you can also try to use two fixed UIImageViews with the images of the hands and use the transform property to apply a rotation.