Use CALayer to change UIButton shape? - iphone

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.

Related

how to create a pointy UIView

I just saw local mind's app and they have a horizontal UIScrollView that has a selection with a pointy tip. How can I create such thing? I saw this often times in many apps where you don't just have a square frame, but you have a pointy edge to it, is this just a UIImage overlayed on top?
Other example would be this
If you disable clipsToBounds in the horizontal UIView (which is default), its subviews are allowed to stick out and draw past the edge of the frame.
Thus, yes, a UIImageView was probably how it was accomplished.
This is most likely achieved using an image. As simple as that.

UIButton - unwanted background well

I'm creating UIButtons (type = UIButtonTypeCustom) with a custom background drawn by an artist; unfortunately UIButton is adding an unwanted 'well' effect around the backgroundImage (as specified via setBackgroundImage). Is there a way to disable the well? It's not a simple drop shadow, so messing with the CALayer properties doesn't seem to help. I realise I could use UIControl, but that's considerably more work, since I need to handle the label subview myself, and get the artist to produce highlighted versions of the artwork - UIButton is doing all that nicely, if I could only disable the well effect.
Put your image inside a UIImageView, and then position your UIButton on top of it. Use the "custom" style, which has no UI to it at all and is totally invisible.
If you want to change ("highlight") your button image when the button is hit, just change the image contained in the UIImageView in whatever method your UIButton targets.

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.

Iphone sdk, Rounded UIImageView FRAME corners, not just masking it

i am building a app in which if a UIImageView hits another something happens, i am using the CGRectIntersetsRect statement, i would like to make it as accurate as i can, at the moment i have about 8 UIImageViews inside this one UIImageView and i am detecting if something hits them 8 little views, i have decided that this is not a very accurate way to go about it. The problem is that the UIImageView the other UIImageView's are in, Its a Oval, so it is complicated, i have tryed masking it, using the
image.layer.radius 10.0 or whatever the code is.
but this doesnt actually transform the whole frame, is there any way to actually transform the whole frame so when a UIImageView hits the Oval shape then something happens?
if so could someone explain it to me.
Thanks
Harry
this is really simple indeed. As a View, UIImageView has a layer and a layer has cornerRadius properties:
imageView.layer.cornerRadius = 5.0;
imageView.layer.masksToBounds = YES;
eBuildy, iPhone specialists
A UIImageView's frame is a CGRect, a CGRect is a rectangle and a rectangle has no rounded properties.

How to configure UIButton to use showsTouchWhenHighlighted?

I have a UIButton that's 90x90 in size and I would like it to glow when tapped. Using showsTouchWhenHighlighted will make it glow but it's glowing out of the center of the button and for a small radius only. This might work well for a small button like the info button, but for my button size, it's not. Is there anything I can do to make it glow from the outer perimeter of the button before I resort to designing a highlighted state?
I can think of 2 ways to do what you want:
Use different highlighted background image for your button's highlighted state,
Use CoreGraphics to draw the glow effect in your button's IBAction (touchDown is a decent place).
This is assuming you want some kind of custom glow effect of course - UIButtons already naturally have a highlighted effect when touched.