自定义UIButton

核心代码如下,具体的请参考附件。

#import "PopoverButtons.h"

@implementation PopoverButtonBottomLeft

- (void)awakeFromNib {
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverBottomArrowLeft"] stretchableImageWithLeftCapWidth:47.0 topCapHeight:35.0] forState:UIControlStateNormal];
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverBottomArrowLeft"] stretchableImageWithLeftCapWidth:47.0 topCapHeight:35.0] forState:UIControlStateHighlighted];
}

@end

@implementation PopoverButtonBottomRight

- (void)awakeFromNib {
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverBottomArrowRight"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:35.0] forState:UIControlStateNormal];
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverBottomArrowRight"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:35.0] forState:UIControlStateHighlighted];
}

@end

@implementation PopoverButtonTopLeft

- (void)awakeFromNib {
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverTopArrowLeft"] stretchableImageWithLeftCapWidth:47.0 topCapHeight:35.0] forState:UIControlStateNormal];
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverTopArrowLeft"] stretchableImageWithLeftCapWidth:47.0 topCapHeight:35.0] forState:UIControlStateHighlighted];
}

@end

@implementation PopoverButtonTopRight

- (void)awakeFromNib {
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverTopArrowRight"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:35.0] forState:UIControlStateNormal];
	[self setBackgroundImage:[[UIImage imageNamed:@"PopoverTopArrowRight"] stretchableImageWithLeftCapWidth:14.0 topCapHeight:35.0] forState:UIControlStateHighlighted];
}

@end

示例图:

猜你喜欢

转载自eric-gao.iteye.com/blog/1716343