Is it possible to create an ActionSheet
that have a label between two buttons like this image?
Really need this right now. Can anyone help me? Thanks.
Is it possible to create an ActionSheet
that have a label between two buttons like this image?
Really need this right now. Can anyone help me? Thanks.
https://github.com/xmartlabs/XLActionController allows us to create any custom action sheet giving much more flexibility than the solutions proposed above.
These are some examples included in the github repository.
If you like Google style and want a lightweight library, you can have a look at this: https://github.com/ntnhon/MaterialActionSheetController
It's totally customizable.
If you're still struggling with this, perhaps this library can help you out: https://github.com/danielsaidi/Sheeeeeeeeet
It's written in Swift and lets you create custom action sheets. It has built-in support for many different items and can be extended and restyled.
If you don't want to use any hacks on UIActionSheet to customize it you can check out a replacement for UIActionSheet that I made: https://github.com/JonasGessner/JGActionSheet It's completely customizable!
EDIT 2018
I posted this code all the way back in iOS4 when it was potentially useful. iOS Development has grown staggeringly since then, please do not use this code unless you are writing an app for iOS4 for whatever reason! Please refer to the wonderful 3rd party library XLR Action Controller for your mondern actionsheet needs!
It is most certainly possible, and I like to do this all the time!
First, make a
@property
of anUIActionSheet
(in this example, mine is calledaac
-- this comes in handy especially if you want to call it byUITextFields
.Next, in the method you bring up the actionsheet, say a
-(IBAction)userPressedButton:(id)sender
, create a local instance of the actionsheet.then add it to your property:
self.aac = actionsheet
Now you basically have full reign to do anything in this ActionSheet, I will give you an abbreviated form of what I did for a recent project:
Here is a picture of what happens (remember I omitted all the other buttons in the code example, but they are pictured here):
Now, if you want to dismiss the actionSheet -- depending on how you set up your button structure, or perhaps use a UIToolBar (very common) -- you can then in the button's selector action, do this:
-(void)cancelButtonClicked:(id)sender { [self.aac dismissWithClickedButtonIndex:0 animated:YES]; }
Also, just FYI, getting all the dimensions just right for your layout will take a little time, as you aren't working with the view of your main UIView of your UIViewController, rather the view of the actionSheet, so it has different dimensions.
One trick I do is layout the actionsheet in Storyboard with a UIView, then place all the objects you want in your "actionsheet" in that UIView, and you should get accurate dimensions for all the images.
Let me know if you need clarification, good luck!