jdl
jdl

Reputation: 6323

How to draw graphics on a UIButton UIButtonTypeRoundedRect?

How to draw graphics on a UIButton UIButtonTypeRoundedRect without subclassing... or do I have no choice? Please note that the graphics around the rounded corners will vary with other functions... so the UIButton cannot interfere... otherwise I could have just used jpg images. Or can I limit the border of the jpg image around the UIButton?

thx

Upvotes: 0

Views: 284

Answers (1)

If I got your question correctly, you need to create an UIButton with an image inside (png or jpg) with rounded corners.

It could be easier if you subclass UIButton (so you can reuse it), but if you don't want to do it, just suppose we have

UIButton *myButton;

pointing to your UIButton with images and other properties correctly setted.

First, don't forget to

#import <QuartzCore/QuartzCore.h>

and then simply set:

myButton.layer.cornerRadius = 5.0f; //or any CGFloat values you need

If it seems not working, check the UIButton "Clip Subviews" property or use:

myButton.clipsToBounds = YES;

Upvotes: 1

Related Questions