What I want is make UIButton adhere to the UIView menu when UIButton isSelected. The black square on UINavigation is UIImage after UIButton selected. My question is how make UIImage (black square) more higher than UIButton after selected?
this my code on UIButton Class .m:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
//...Our red stretchy
UIImage *redImage = [UIImage imageNamed:@"button_red.png"];
UIImage *redStretchy = [redImage stretchableImageWithLeftCapWidth:redImage.size.width / 2 topCapHeight:redImage.size.height / 2];
//...Initialization code
[self setFrame:frame];
[self setTitle:TITLE forState:UIControlStateNormal];
[self setBackgroundImage:redStretchy forState:UIControlStateNormal];
[[self titleLabel] setFont:[UIFont boldSystemFontOfSize:FONT_SIZE]];
[[self titleLabel] setShadowOffset:CGSizeMake(FONT_SHADOW_OFFSET, FONT_SHADOW_OFFSET)];
//...add target
[self addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
this the target methode:
//...add target
- (void)actionButton:(id)sender {
if ([sender isSelected]) {
} else {
CGSize buttonSize = CGSizeMake(self.frame.size.width, self.frame.size.height);
[sender setImage:[self imageButton:buttonSize] forState:UIControlStateSelected];
}
if (delegate != nil && [delegate conformsToProtocol:@protocol(ButtonProtocol)]) {
if ([delegate respondsToSelector:@selector(actionButton:)]) {
[delegate performSelector:@selector(actionButton:) withObject:sender];
}
}
}
and this methode create UIIMage:
//...create image button
- (UIImage *)imageButton:(CGSize)size {
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef currentContex = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGRect firstRect = CGRectMake(0.0f, 0.0f, 60.f, 30.0f);
CGPathAddRect(path, NULL, firstRect);
CGContextAddPath(currentContex, path);
UIColor *fillColor = [UIColor blackColor];
CGContextSetFillColorWithColor(currentContex, fillColor.CGColor);
CGContextDrawPath(currentContex, kCGPathFill);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}