Monday, June 17, 2013

UIActionSheetDelegate didPresentActionSheet example in Objective C (iOS).


UIActionSheetDelegate didPresentActionSheet

Sent to the delegate after an action sheet is presented to the user.

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet

Parameters of [UIActionSheetDelegate didPresentActionSheet]
actionSheet
The action sheet that was displayed.

UIActionSheetDelegate didPresentActionSheet example.
You can't redraw the border in a different color, so just remove the border and add your own:

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet {
    UIView *contentView = actionSheet.superview;
    UIView *popoverView = contentView.superview;

    UIView *chromeView;
    for (UIView *v in [popoverView subviews]) {
        if (v.subviews.count == 3) {
            chromeView = v;
            break;
        }
    }

    for (UIView *backgroundComponentView in [chromeView subviews]) {
        backgroundComponentView.hidden = YES;

        CGRect componentFrame = backgroundComponentView.frame;  // add your view with this frame
    }
}
Note that this won't work in *will*PresentActionSheet since actionSheet doesn't have a superview set at that point.

Example of [UIActionSheetDelegate didPresentActionSheet].
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet{
CGRect rect = CGRectMake(0,0, 320, 480);
UIButton* anImage = [[UIButton alloc] init];
[anImage setTitle:@"GHello worl" forState:UIControlStateNormal];
[anImage setTitle:@"GHello worl dfasd" forState:UIControlStateHighlighted];
[anImage setTitle:@"GHello worl selected" forState:UIControlStateSelected];
//[anImage setBackgroundImage:[UIImage imageNamed:@"photo.png"] forState:UIControlStateNormal];
[anImage addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
rect = CGRectMake(0,0, 320, 220);
anImage.frame =rect;

[actionSheet.superview addSubview:anImage];

[anImage release];
}

End of UIActionSheetDelegate didPresentActionSheet example article.