Reputation: 23223
I'm trying to make a UIButton
with a background image where the image is larger than the button frame.
The problem is, the UIButton
automatically scales the image to fit and haven't found a way to change the behavior.
Am I missing something obvious or is it time to make a custom button?
Upvotes: 0
Views: 1194
Reputation: 340
Subclass UIButton and override the
- (CGRect)backgroundRectForBounds:(CGRect)bounds;
method so it returns the size you want.
TIP: Use this method to center your background as well.
Upvotes: 2
Reputation: 23223
Looks like the answer to this one is. Not possible through existing interface on UIButton
.
The simplest way to implement seems to be using a custom sub class of UIButton
and creating a UIImageView
with the same frame as the UIButton
, turn off clipping and scaling and then just capture all the setBackground
methods and capture state changes to handle "normal" button interaction changing the background images.
Upvotes: 0