0

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?

screenshot

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;
}
devnull
  • 118,548
  • 33
  • 236
  • 227
Sukma Saputra
  • 1,539
  • 17
  • 32
  • 1
    [This is the same question you asked a few minutes ago](http://stackoverflow.com/questions/17584879/home-make-uiview-adhere-to-the-uibutton). You should delete that first question or delete this question and fix up the other question. Asking the same question many times isn't a good thing. – Michael Dautermann Jul 11 '13 at 04:39
  • 2
    more higher than UIButton didn't get u pls elaborate – Prince Kumar Sharma Jul 11 '13 at 05:14
  • if i m assuming your requirement correctly than you need image that set in UIButton higher on button selection.if you set image in button than you can use UIButton's UIEdgeInsets property that allow you set inset and ousset for top,bottom,right,left. refer this link to understand edgeinset http://stackoverflow.com/questions/1781256/how-to-use-uiedgeinsets-property-in-button-in-iphone hope that help you – user1548843 Jul 11 '13 at 06:02
  • thank user1548843 its work perfectly. – Sukma Saputra Jul 12 '13 at 02:53

0 Answers0