自定义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

 

示例图:

自定义UIButton

你可能感兴趣的:(ios,iPhone,UIButton)