Question

I need to add images on action sheet buttons so I used following code

UIActionSheet *actionSheetObject = [[UIActionSheet alloc] initWithTitle:@"Follow Us" delegate:self cancelButtonTitle:kCancel destructiveButtonTitle:nil otherButtonTitles:@"Twitter",@"Facebook",@"Blog",@"LinkedIn",nil];
[[[actionSheetObject valueForKey:@"_buttons"] objectAtIndex:0] setImage:[UIImage imageFromBundle:@"TwitterIcon"] forState:UIControlStateNormal];
[[[actionSheetObject valueForKey:@"_buttons"] objectAtIndex:1] setImage:[UIImage imageFromBundle:@"FacebookIcon"] forState:UIControlStateNormal];
[[[actionSheetObject valueForKey:@"_buttons"] objectAtIndex:2] setImage:[UIImage imageFromBundle:@"BlogIcon"] forState:UIControlStateNormal];
[[[actionSheetObject valueForKey:@"_buttons"] objectAtIndex:3] setImage:[UIImage imageFromBundle:@"LinkedInIcon"] forState:UIControlStateNormal];
[actionSheetObject showInView:self.view];

OutPut enter image description here

But My question is it the correct way to achieve this? Means Apple will accept my app on appstore?

Was it helpful?

Solution 2

99.9% is that Apple will accept this, because compiler will not detect no warnings about this, but there is other problem, Apple can change the name of variables in the UIActionSheet, I mean, this code is risky, but definitely will work and pass the Apple validations.

OTHER TIPS

Don't use private API's, if you want to put your app on AppStore. Apple will reject the app's that use private API's.

According to UIActionSheet Documentation:

UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:.

As an alternative way you can use a customized UIView with these UIButtons. When it is displayed, you can disable the touch events of parent view, so that it will act same like action-sheet.

Here is an example: Display a custom UIView like a UIActionSheet

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top