UIAlertView (or LMAlertView) with two stacked buttons - ios

How can I create an UIAlertView with two stacked button? Instead of two buttons side by side? In my project I also use LMAlertView (GitHub repository) and I thought it would support them, but I can't find a way to obtain that very UIAlertView style.
Currently I create a UIAlertView with this code below:
LMAlertView *applicationUpdateAlert = [[LMAlertView alloc] initWithTitle:alertTitleFromServer
message:alertMessageFromServer
delegate:self
cancelButtonTitle:NC(#"Aggiorna ora")
otherButtonTitles:NC(#"Ricordamelo piĆ¹ tardi"), nil];
[applicationUpdateAlert show]
I don't know if this can be useful for you to better understand but LMAlertView has a property named buttonsShouldStack which I thought it would be useful for me but I can't properly use it, this is the code related to buttonsShouldStack in LMAlertView.m file (direct link):
- (void)setButtonsShouldStack:(BOOL)buttonsShouldStack
{
_buttonsShouldStack = buttonsShouldStack;
if (self.numberOfButtons == 2) {
[self.buttonTableView reloadData];
[self.otherTableView reloadData];
}
}
Thanks

Maybe you can give a try with this library. It has a demo project that cover your needs.

I fixed the problem by "rewriting" the LMAlertView component in order to treat UIAlertView buttons as UITableView's cells and by setting the rowNumber accordingly, if the alert has to show 1, 2 or more buttons. It's not an easy to show solution so I won't share the code here, also because I don't know if it's Apple's-approval safe.
Thanks to everyone!

Related

How to Customize iCarousel Coverflow like below in iOS?

I have to present a view like this in the picture :
I remember that iCarrousel project can do such things, Could Any one guide me to the right control that provide this animation?
I Tried and Got Something like this
Thanks.
You need to adjust the tilt of the item views, which can be done using the carousel:valueForOption:withDefault: delegate method, like this:
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
if (option == iCarouselOptionSpacing)
{
return value * 1.5;
}
else if (option == iCarouselOptionTilt)
{
return 0.2;
}
return value;
}
The values included are just example. You'll need to tweak the title, and probably also the spacing, to avoid having the items appear to pass through each other.
The iCarousel repo includes several demo projects, one of which includes the option to display all the different types of Carousels it offers. It's been a while since I've used it, but I'm pretty sure one of the options is what you're after.
I suggest going through the demo programs and looking for the carousel type that matches what you want. Then there are a multitude of settings that you can adjust to customize the look of the carousel.

Should UIAlertView be subclassed?

I am sure the answer to this is "no" as the documentation is very clear. But I am a little confused. A standard UIAlertView is pretty dull and I want to improve the look and it seems that other apps do it (see the example below).
Another possibility is that they are not subclassed UIAlertViews. In which case, how is this achieved?
The page UIAlertViews states
Appearance of Alert Views
You cannot customize the appearance of alert views.
So how do we get the something like the example shown here?
No, do not subclass it. From the docs:
Subclassing Notes
The UIAlertView class is intended to be used as-is
and does not support subclassing. The view hierarchy for this class is
private and must not be modified.
What you can do though is create a UIView and have it act similar to a UIAlertView. It's isn't very difficult and seems to be what they are doing in your op.
Apple's docs say that you should not subclass it. That means that there are probably internal reasons that would make it difficult to make it work right.
You might or might not be able to make a subclass of UIAlertView work, but you do so at your own risk, and future iOS releases might break you without warning. If you tried to complain Apple would laugh and tell you "I told you so".
Better to create a view that looks and acts like an alert but is your own custom view/view controller. Beware that even this is dangerous, because Apple has been making sweeping changes to the look and feel of it's UI elements recently. If you implement a view controller that looks and acts like a variant of the current alert view, Apple could change that look and/or behavior in the future and your UI app would end up looking odd and outdated. We've been bitten by this sort of thing before.
Rethink your strategy. Why do you need to use an Alert View? Besides having a modal view displayed top-most on your view stack, there's not much else that it does. Instead, subclass UIView or UIViewController to define your own interface, using images and ui elements to give it the style and input functionality as needed.
I usually subclass UIView, and attach it to the app's window's view so that I'm certain that it will be displayed on top of anything else. And you can use blocks to provide hooks into the various input elements of your new view (did user press OK, or did user enter text?)
For example:
// Instantiate your custom alert
UIView *myCustomAlert = [[UIMyCustomUIViewAlert alloc] initWithFrame:CGRectMake(...)];
// Suppose the new custom alert has a completion block for when user clicks on some button
// Or performs some action...
myCustomAlert.someEventHandler = ^{
// This block should be invoked internally by the custom alert view
// in response to some given user action.
};
// Display your custom alert view
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window addSubview: myCustomAlert];
// Make sure that your custom alert view is top-most
[window bringSubviewToFront: myCustomAlert];
Using this method, however, will not pause the thread's execution like UIAlertView does. Using this method, everything will continue running as usual. So if you need to pause execution while your custom alert is showing, then it gets much trickier.
But otherwise, creating your own custom alerts is quite straightforward, just as you would customize any other view. You could even use Interface Builder.
Hope this helps.
No. You absolutely should not subclass a UIAlertView for any reason. Apple explicitly states this in their documentation (see "Subclassing Notes"). They even tell you that it relies on private methods - and we all know that meddling in private methods in an AppStore app is immediate grounds for rejection.
HOWEVER, there isn't a need to subclass UIAlertView on iOS 7. Apple introduced a new Custom ViewController Transitions feature in iOS 7.0 that lets you present completely custom ViewControllers with completely custom transitions. In other words, you could very easily make your own UIAlertView or even something better. There's a nice tutorial on the new feature here:
In fact, there are lots of good tutorials on this - a quick Google search on the topic turns up a huge wealth of information.

How to create a flat UIActionSheet

Today's trend in apps includes flat designs, and now I am doing an app that follows with this trend. My problem now is how to create a UIAcionSheet that match with my App Screen's flat UI Design. In relation with this, I saw Instagram's action sheet and I found it interesting. I wish to have that design in my app. Anyone knows how to implement this in ios apps? I have provided a screen shot from instagram app.
You can use RDActionSheet from git
https://github.com/reddavis/RDActionSheet
I hope it will help you..!!
yes,
you can use https://github.com/reddavis/RDActionSheet and also u can change image and color of text and background image of action sheet
You can use FlatUIKIT from Git
https://github.com/Grouper/FlatUIKit
Go through the documentation & you will know how to use it. Awesome collection of Flat UI classes.
You can create a subclass CustomActionSheet derived UIActionSheet,
and create a method called CustomUI in it. Design your code here.
use CustomActionSheet like UIActionSheet, except must call method CustomUI of subclass in willPresentActionSheet delegate:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
if ([actionSheet isKindOfClass:[CustomActionSheet class]]) {
CustomActionSheet *sheet = (CustomActionSheet*)actionSheet;
[sheet CustomUI];
}
}

disable CPPickerView not working

I'm making an iPhone/iPad app where I have PickerView. For PickerView, I am using CPPickerView.
I'm trying to disable this pickerview and to do that, I wrote this code:
[realEstatePV setUserInteractionEnabled:NO];
However, above is not working. I can still move the CPPickerView.
Any idea how to get this done?
I had the same problem. So i updated the CPPickerView, and its very easy.
Open CPPickerView.h and add a method declaration
- (void)enabled:(BOOL)val;
Now open CPPickerView.mand add implementation method.
-(void)enabled:(BOOL)val {
self.contentView.scrollEnabled = val;
}
Its done......
Now You can disable CPPickerView like this.
[realEstatePV enabled:NO];
To enable again use
[realEstatePV enabled:YES];
Hope this helps.

I need to figure out multiple UIActionsSheets?

I am trying to create multiple UIActions sheets with my view. I have read a few questions on here and browsed the internet, but nothing seems to get me a valid answer.
I have tried the "switch and case" method that looks like this....
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (actionSheet.tag) {
case 10:
if(buttonIndex == 0)
{
and I have tried this method too...
UIActionSheet *actionSheet1;
UIActionSheet *actionSheet2;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{
if(actionSheet==actionSheet1)
{
The action sheet options work as individuals, so I know that the links and code is right, but I can't seem to get them both to work at the same time.
Let me know if I need to post more code.
Cheers Jeff
More Info:
-(IBAction)Action01:(id)sender {
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:#"Please Choose a Website:" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Facebook",#"Twitter",#"Google Maps",nil];
actionSheet1.tag = 10;
[actionSheet1 showInView:self.view];
}
and the second one is set up with tag = 11.O have also linked the buttons in Interface Builder with the same tag number.
In my heads file, I have defined my properties and IB Actions as well. Everything is done properly as it works if i use only one or the other of the action sheets and comment the rest out.
Here are the links to the files if it makes them easier:
Header file
Implementation file
Cheers Jeff
You mention in your updated post that you have set the tags in Interface Builder and in code. This is likely causing a conflict. You don't want those IB buttons to have the same tags as the action sheet, or strange thing will happen.
Change the tags in Interface Builder and that should solve your problem.

Resources