Create Custom button like human Hand - iphone

As a part of my app i need to fire a method while clicking any where inside a human hand image. Human hand image is placed in a image view. i need to add a button in-spite of adding gestures. Is it possible to create a custom button like human hand exactly show in the image below?
thanks

Create a custom UIButton add the image hand as its backgroundImage or setImage. Then use /assign this image inside. Like below:
handButton = [UIButton buttonWithType:UIButtonTypeCustom];
[handButton addTarget:self action:#selector(handImage_touch) forControlEvents:UIControlEventTouchUpInside];
[handButton setBackgroundImage:[UIImage imageNamed:#"handIMAGE.png"] forState:UIControlStateNormal];
handButton.frame = CGRectMake(x, y, width, height);
[self.view addSubview:handButton];
-(void)handImage_touch{
// do anything
}

I think at first you have to make polygon which fit to your image. And then you can use touchesBegan:withEvent: to get the coordinate of touch point and judge whether the point is inside of polygon or not.
Here is similar question like yours.
How to get particular touch Area?
I think this is a little difficult work, so maybe you would better use cocos2d library which have collision judgement function.
http://box2d.org/forum/viewtopic.php?f=9&t=7487
But also I think iOS is well constructed for handling touch, so this is beneficial effort for you.

Related

IOS Custom UIButton

I currently work on a small application in which I have several UIButtons. Each of them has an UIImageView beneath it. At the moment, I associate each UIButton with each UIImageView (all are named via an IBOutlet - UIButton and UIImageView). When I press a button, the underlying image changes. I would like to know if it's possible (and how) to create a button which contains an underlying UIImage (not a UIButton image or background image), a sort of new object.
This image is slightly larger than the associated UIButton, like the apple calculator basic apps, and this image changes when I press the button.
I've tried several solutions (certainly incomplete) and I'm beginning to despair.
My current solution is functional but I do find it not particularly elegant.
UIButton has both image and backgroundImage as its properties.
To achieve what you are looking for, I would actually recommend you to stick to just a UIButton, and then using contentInset to position the image over the backgroundImage so it creates the effect I think you are looking for. This should be quite easy in interface builder...
you can make an invisible button and behind it make the image..
This will give you what you want but should be avoided at cost...
Stick to UIButton..
I believe even in calculator app they are only UIButtons and nothing else..
they have been coded to been momentary selected ..so that's why you see them kind of changing highlight for a small fraction and each button have been coded to perform specific function(+ - / equal .)
Update : i might be in doubt but if you asked for a button to have an image view inside it..
then here is the answer.
Make UIbutton. Make an ImageView and then call [theButton.view addSubview:ImageView];
Since both UIbutton and UIImage view inherit from UIView.. you can add as many subviews to them..that is inside them
If I understood your question correct then you may try the following:
UIButton *button = [UIButton alloc]init];
[button setImage:buttonImage forState:UIControlStateNormal]; when button not pressed
[button setImage:buttonImage forState:UIControlStateSelected]; when button tapped
[button release];

Question on iPhone Development Custom UI

So on the App Store, what I'm seeing a lot is a custom UI that still looks like the native Apple ones, but is some how "spruced up" in look. How exactly would I create something like that, as in say a button that is a hexagon or something instead of a rounded rectangle?
Thanks,
VectorWare
Draw any image you want, using your favorite art program.
Don't forget to make pressed and "up" states.
Create your button (in IB or code.)
Make the button of type UIButtonTypeCustom (IB or code.)
In IB, set the button's image to your image.
Set the image separately for NORMAL and HIGHLIGHTED states (IB or code.)
Example in code:
[myButton setImage: myImage forState: UIControlStateNormal];
They are probably either subclass' of UIView/UIWhatever or images with a transparent UIButton over top of the image. Is there something specific you want to implement?
Some examples:
Subclassing a UIView
UIView subclass dialog window

Creating pixel perfect standard UIBarButtonItem with custom image inside

I've been scratching my head over this for the past couple of hours. Is it possible to create a standard UIBarButtonItem with a custom image inside? All I want is the standard blue button, but with an image that represents preferences (a screwdriver or cog wheel that I'll create myself) inside of it. I'd rather not use Photoshop to do this, since I'd like every single pixel to be perfect and future proof, in case Apple releases even higher resolution iOS devices.
I've found a wonderful project on GitHub that includes every graphic element shipped with iOS, and I've extracted what appears to be the image Apple itself uses when creating standard UIBarButtonItems. Problem is, it can't be resized to the proper dimensions in a way that I know of. In case it's not possible to do what I want with code, then maybe someone can tell me how to use this image.
GitHub - UIKit-Artwork-Extractor
UINavigationBarDefaultButton#2x.png
Thanks!
Just create your image, in a single color (only the alpha channel is significant) and use initWithImage:style:target:action: with the UIBarButtonItemStyleBordered or UIBarButtonItemStyleDone style.
If you want a full-color image, you'll have to use the image you linked. The secret is to resize it by duplicating the "middle" column and row of pixels in the style of an Android 9-patch image, rather than by scaling the entire thing.
Images like that are used by making them stretchable. Basically, you want only the middle of the image to be stretched when you resize the image, while the left and right cap should not be scaled, to avoid distortion.
UIImage *buttonImage = [UIImage imageNamed:#"UINavigationBarDefaultButton.png"];
UIImage *stretchableButtonImage = [buttonImage stretchableImageWithLeftCapWidth:5 topCapHeight:0];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:stretchableButtonImage forState:UIControlStateNormal];
In your case however, why don't you just use a UIBarButtonItem with the UIBarButtonItemStyleDone or UIBarButtonItemStyleBordered as its style?

Use CALayer to change UIButton shape?

I know how to build a round UIButton by using the cornerRadius of the CALayer of a UIButton.
col1 = [UIButton buttonWithType:UIButtonTypeCustom];
col1.layer.cornerRadius=w/2;
col1.layer.masksToBounds=YES;
Is there a way to do more interesting things about the boundary like chop off half a corner with CALayer?
Any examples?
I'm not sure what you mean by chop off half a corner, but the only other interesting thing you can really do to change the shape of a button using CALayer is setting the mask property. Be careful, though, as this is a fairly significant performance hit, plus it won't affect the touch behavior of the button at all, only the visual.
In general, you should be setting custom background images for your buttons if you want to change how they look.

can i add progress into a UISlider?

This picture shows what i want , i just making a custom movieplay controller.
alt text http://www.imagechicken.com/uploads/1279252703012036800.png
I know how to make a custom uislider as code below
playSlider.backgroundColor=[UIColor clearColor];
[playSlider setThumbImage:[UIImage imageNamed:#"sliderButton.png"] forState:UIControlStateNormal];
[playSlider setMaximumTrackImage:[UIImage imageNamed:#"sliderGray.png"] forState:UIControlStateNormal];
[playSlider setMinimumTrackImage:[UIImage imageNamed:#"sliderBlue.png"] forState:UIControlStateNormal];
but that can not help me .Is there any ideas? Thank you for any advices!
I think you could get away with a UISlider only if the thumb was never allowed to leave the blue (loaded) area. Then you could draw the inactive (unloaded) track to the right of the actual slider bounds, and just update the bounds for the slider as the video loads, which would increase the blue area. But you'd still have to do the right math for the slider thumb's relative progress.
If you need the thumb to swipe into the unloaded area, or you want to avoid a headache with the recalculation, you should just build your own control. Unfortunately, the UISlider is not a highly customizable control by itself.
You should be able to subclass drawRect on the UISlider to customize that, but I may be wrong.
overriding drawRect: is not a good idea.
You will have to make a custom object containing something like:
an UIButton for the play/pause, an UISlider for the slider, an UIButtons for the mute on/off,
and a UIView for the volume (you will have to implement by your self)
Actually is not difficult, is just an container object.