Возможно, немного поздно, но если кто-то сталкивается с этим, есть и другая возможность без использования изображений. Вместо этого я использую QuartzCore.
Вот что я делаю:
MyUIButton.h
#import <QuartzCore/QuartzCore.h>
@interface MyUIButton : UIView { //i think you can also subclass from UIButton, but i use a view to be more flexible
UIButton *_myInnerButton;
}
- (void) addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
- (void) removeTarget:(id) target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
@end
MyUIButton.m
#import "MyUIButton.h"
@implementation MyUIButton
- (void) dealloc {
if (_myInnerButton != nil) {
[_myInnerbutton removeFromSuperview];
_myInnerbutton = nil;
}
[super dealloc];
}
- (id) initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
_myInnerButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:_myInnerButton];
CGRect innerButtonRect = CGRectZero;
innerButtonRect.size = self.frame.size;
_myInnerButton.frame = innerButtonRect;
CGRect iOSLookalikeViewRect = innerButtonRect;
iOSLookalikeViewRect.origin.height = -innerButtonRect.size.height/2;
UIView *iOSButtonView = [[UIView alloc] initWithFrame:iOSLookalikeViewRect];
iOSButtonView.layer.cornerRadius = 3;
[self insertSubview:iOSButtonView belowSubview:_myInnerButton];
UIColor *whiteColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.3];
UIColor *whiteColor2 = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.1];
[self setGradientColors:[NSArray arrayWithObjects:whiteColor.CGColor, whiteColor2.CGColor, nil] forView:iOSButtonView];
[iOSButtonView release];
}
return self;
}
- (void) setGradientColors:(NSArray*) gradientColors forView:(UIView*) view {
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = gradientColors;
gradient.cornerRadius = view.layer.cornerRadius;
[view.layer insertSublayer:gradient atIndex:1];
[view.layer setRasterizationScale:[UIScreen mainScreen].scale]; //Optional for performance issues, can be removed also
}
//Implementation of the public methods not included, but just asign the methods to the _myInnerButton
@end
Надеюсь, это кому-нибудь поможет