iphone - how to extend a button touch area? - iphone

I have 5 round buttons in a row, each one, 40x40 pixels. Between each one, I have 20 pixels.
40x40 pixels is too small to touch, but as I have 20 pixels of space between each button I can extend the button touch area to 60x60 pixels, making it easy to touch. I could simply using the dirty solution of creating a square 60x60 pixels transparent image, put this over the button and make this touchable, but I know it is possible to extend a button touch area by creating a custom class and changing a parameter.
I know this is possible because I saw this done before (but I cannot find the URL). I know it is something related to hitTest.
How can this be done?
Thanks.

Eiko is absolutely right. Here's some simple code you can use that is independent of the button's location that somebody gave me for expanding the Info button frame.
CGRect newInfoButtonRect = CGRectMake(infoButton.frame.origin.x - 25,
infoButton.frame.origin.y - 25,
infoButton.frame.size.width + 50,
infoButton.frame.size.height + 50);
[infoButton setFrame:newInfoButtonRect];
You might want to watch out if you're using a background image as opposed to an image ( button setBackgroundImage: vs button setImage: forState:) because a background image will stretch with the frame while a normal image will not.

You can always make its frame bigger, i.e. yourButton.frame = CGMRectMake(0,0,60,60);
I usually do this when adding one of the info buttons.

Related

touch button aerea (iPhone,iPad)

I have got this situation:
this is the photo: http://imageshack.us/photo/my-images/826/iconepe.png/
the two images are little 20 pixel x pixel, If I click on them, nothing happens, if I click oh the left on them, the link works. I should make images bigger?
My guess is that you are missing the buttons with your finger.
The comfortable minimum size of tappable UI elements is 44 x 44
points.
According to the iOS Human Interface Guidelines
If you need to keep the images this small, one workaround would be to increase the size (frame) of the button and keep the image (the image must be set as a button image, not background image). This way you'd have a bigger zone that will accept input and still use the same image.
Ask your designer to make the image bigger, by using a transparent space around it.. 20x20 is too small to touch.. Apple says that the avg finger tap is 44x44 (from WWDC). All table rows are recommended to be at least that height. Use a transparent padding to make your image atleast 44 * 44.

How do I use a non-stretchable, but repeating background image for UISlider track?

Is it possible to set a track image for the UISlider which does not strech, but repeats itself?
I have a background image with small position points (the attached image is exmaple... mine is horizontal). So if the UISlider is longer than the image itself, it starts to stretch it and the position points are not symmetrical any more. Would be really nice that if the slider or the thumb exceeds track image width, then it just repeats itself.
Something similar to css background-repeat: repeat-x;
You can use - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets.
It only works on iOS 5 and later though.

UI Button with Image Smaller than Touchable Area

I've not much response so am adding some more info.
My buttons are not rectangular, nor organised in a grid so I need a way of creating what looks like a button (and shows that it has been pressed visually, as per a standard UIButton) but where the touchable area is different to the image area.
I am using a transparent PNG and that element works fine. I've added the buttons in Interface Builder and am wondering if that is the problem.
However, if I change imageEdgeInsets, it distorts the image display, which is obviously not what I want.
Bizarrely, if I increase the dimemsions of the button, it doesn't change the image, but if I decrease them it does.
I have tried different combinations of mode (scale to fill etc), but to no avail.
I am aware that there is an image and background image property, but in IB there is only one.
Essentially, I don't understand how the geometry works and the Apple documentation doesn't seem to help.
Surely, I can't be the only person to try to do this. Any help would be warmly welcomed.
Many thanks,
Chris.
Try setting the buttons setting to Aspect Fit. This will fill the button with your image so a smaller image than the button size would leave the space around the image.
Also set the button type to custom.
In the end, I stumbled across Ole Begemann's Non-rectangular buttons class. It just does what I need - to be able to create buttons where the touchable area follows the visible element of a non rectangular image.
#Helium3 - thanks - that allowed me to use a larger touch area, bit not a smaller one.

Free bitmaps for iOS custom buttons and sliders?

First, I'm not talking about icon libraries or mockup tools/libraries.
I'm familiar with various icon libraries that people have created, but other than the stuff from the example code like UICatalog, I'm wondering if anyone knows of anyone who has created free libraries of custom button bitmaps (stretchable button images), slider handle/track bitmaps, etc Basically bitmaps to customize the look of standard controls for those controls (like buttons and sliders) that allow you to specify such bitmaps.
I'm also interested in any photoshop tutorials/templates on/for creating stretchable custom button images, bitmaps for slider parts, etc. (Afraid I'm not a huge PS god or anything.)
Anyone know of any resources like this for fancying up the standard controls?
I've been able to find several stretchable buttons by searching through my collections of sample code for: "stretchableImageWithLeftCapWidth"
From the Apple sample code, the UICatalog, BubbleLevel, iPhoneMultichannelMixerTest, avTouch, AQOffilineRenderTest, and TouchCells sample code all contain buttons with stretchable images.
Hope this helps!
Stretchable buttons is no problem - there's nothing special you need to do in Photoshop. Just make the image of the button stretchable and set the radius to that of any rounded corners you have on the button graphic.
Slider parts - I'm pretty sure you'd have to make your own UIControl from scratch.
To make a button in Photoshop, create a new file with transparent background, select the Shape tool, rectangle near the bottom of the tools, drag out a rectangle. Size doesn't matterâ„¢. For a rounded rectangle, click and hold the same tool, choose the rounded rect shape and set a corner radies (same radius as in stretchableImage later).
Double-click the layer right of the layer name to get the layer style popup. Check Color Overlay and set the color you want. Check Inner Bevel and make its size somewhere below half the height of the rectangle - I think 90 degrees for the Global Angle works well. A lower opacity and larger size makes the bevel look less chunky.
Ctrl-click (option-click) the graphics rectangle in your layer to select the button's outline. Deselect the bottom half of it by using the marquee tool (M) at the top of the tools. Select a light gray foreground color, nearly white. Create a new layer with the square icon under the layer list (Windows->Layers if not visible). Fill the selection of the new layer with the paint bucket, and drag down opacity for the layer until the 'matte laquer' effect of it looks right.
A simple button, but that's the gist of it.

iPhone - UIButton background image is cut off sometimes

I am using a custom image as the background image for my buttons. I have noticed that the edges of the buttons are cut off sometimes. My buttons vary in size but the behavior doesn't seem to be dependent on the button size. I am creating the buttons programatically. The image I am using is pretty large to cover the entire background.
Can someone please let me know what could be the issue?
More info
Setting the content mode to UIViewContentModeScaleToFill still cuts of the images. Also tried resizing the image but doesn't make a difference.
Thanks.
Did you try setting the button's dimensions to fit exactly the image?
Is the image just cropped or also blurry (cause it's being resized)? Have you toyed around with UIView's contentMode property for the button?
If you did, did you try increasing/decreasing the width or height by a pixel? I sometimes had blurry buttons even though its dimensions were exactly the image's. Adding or removing an extra pixel sometimes helped.
I finally resolved this by creating a 3x3 px image with the background color as the button's color and a 1 px border surrounding the image. Then used the UIImage method stretchableImageWithLeftCapWidth:topCapHeight: to create an image with the desired border size of 1 px.