checkbox in uialertview in ios8 - ios

I want to add checkbox exactly as the below image
below is my code:
UIButton *nameField = [[UIButton alloc] initWithFrame:CGRectMake(120, 0, 30, 30.0)];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
[v setBackgroundColor:[UIColor clearColor]];
[nameField setImage:[UIImage imageNamed:#"unchecked.png"] forState:UIControlStateNormal];
[v addSubview:nameField];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Delete selected pods from server?" message:
#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[av setValue:v forKey:#"accessoryView"];
av.message = #"This will delete all the posts related to the pictures you want to delete!";
[av show];
with the above code I am getting as :
I want to get checkbox beside message..
Any help or suggestion how to proceed?

You can use https://github.com/wimagguc/ios-custom-alertview
Create your custom content view and set it like
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
UIView *customView ..; //Your custom view
[alertView setContainerView:customView];

I would suggest you to do not do that.
accessoryView is not a public exposed API and you risk an app rejection
UIAlertView is deprecated in iOS8, use UIAlertController
You can use a third party library, I usually integrate MRProgress in my projects, you can create your own nib and add it.

Related

How to create UIProgressViewStyleBar on UIAlertview iOS 7?

I am trying to create UIProgressViewStyleBar on UIAlertview with JSON loading status info on my app. Now my problem is I cant see UIProgressViewStylebar on iOS 7. Please help me!
My Source:
UIAlertView *alertss = [[UIAlertView alloc] initWithTitle:#"Please Wait..Downloading reports..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ;
alertss.frame=CGRectMake(50, 50, 280, 40);
UIProgressView *prgView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
prgView.frame = CGRectMake(5, 0, 70, 20);
prgView.hidden=NO;
[alertss addSubview:prgView];
[alertss show];
UILabel *statusLabel = [[UILabel alloc] init];
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.textColor = [UIColor whiteColor];
statusLabel.font = [UIFont fontWithName:#"AmericanTypewriter-Condensed" size:18.0];
statusLabel.frame = CGRectMake(120, 80, 80, 20);
[alertss addSubview:statusLabel];
[alertss show];
Yeah that is the correct code with that code add this line
[progressView setProgress:0.75f animated:YES];
before showing your alert. change the progress value depends on your need. or animate it if you want.
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
UIProgressView* progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[progressView setProgress:0.75f animated:YES];
// you have to set the accessoryView to alertview
[av setValue:progressView forKey:#"accessoryView"];
[av show];
see adding MBprogressHUD is so simple. first download the MBProgressHUD Lib from the GitHub and import in your project as #import "MBProgressHUD.h"
And then simple line to show the progressHUD is as follows :
to show:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
to hide:
[MBProgressHUD hideHUDForView:self.view animated:YES];
for your problem use this code:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[av show];
[MBProgressHUD hideHUDForView:self.view animated:YES];
Here I used the circular loader. if you want to customise it you can use this loader in many forms as you wish.

UIActionSheetdelegate not getting subviews

In my iOS 8 application I am using UIActionSheet. I tried to change the color of the button title in willPresentActionSheet delegate method, but it is not recognizing buttons as its subview.
I constructed UIActionSheet like this:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:#"Select an Option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
popup.tag = 2;
[popup addButtonWithTitle:#"Add Tag To Chat"];
[popup addButtonWithTitle:#"Remove Tag From Chat"];
[popup addButtonWithTitle:#"Terminate"];
[popup addButtonWithTitle:#"Cancel"];
[popup showInView:self.view];
Delegate is:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(#"%d",[actionSheet.subviews count]);
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}
Buttons are showing, I can click and action performs. But it says count = 0. Why?
Try this way, changing the UIColor of subviews:
UIActionSheet * action = [[UIActionSheet alloc]
initWithTitle:#"Title"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"",nil];
[[[action valueForKey:#"_buttons"] objectAtIndex:0] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
I've tried it. It is working...
The delegate methods in which you're trying to check the number of subviews: willPresentActionSheet seems inappropriate.
willPresentActionSheet is called before the action sheet actually gets rendered.
If you check the number of subviews in didlPresentActionSheet, that will be more appropriate.
Hope this helps..

Adding UIActivityIndicatorView to UIAlertView

I want to add an activity indicator inside the message , the uiAlert message, i tried basically everything on the internet, and nothing worked for me, i will just have the uialertview alone , here's my code
UIAlertView *waitAlert = [[UIAlertView alloc] initWithTitle:#"Please Wait...." message:#"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
progress.color = [UIColor blackColor];
[waitAlert addSubview: progress];
[progress startAnimating];
[waitAlert show];
This is what i end up having
what am i missing!?
in iOS 7 you cannot addSubview anything on UIAlertView,that was possible till iOS 6.1.so MBProgressHud is the best and simple solution for that
Try to add your UIActivityIndicator using the UIAlertViewDelegate method:
- (void)didPresentAlertView:(UIAlertView *)alertView
{
UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
progress.frame = CGRectMake(125, 50, 30, 30);
[progress startAnimating];
[alertView addSubview:progress];
}

iPhone - AlertView text field shifts using iOS6 [duplicate]

This question already has answers here:
UIAlertView with textfield and three buttons issue in ios 6
(4 answers)
Closed 9 years ago.
I have a problem with my UIAlertView text field using iOS6.
The text field shifts all the way to the top. When i use iOS7, the text field is in the right spot.
Can someone help me? Here is the code:
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Item?"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Add another", #"Done",nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeWords;
[message show];
The text field appears on the title text (here: Item?)
did you try this :
-(void)willPresentAlertView:(UIAlertView *)alertView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
{
[alertView setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alertView subviews];
UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
[message setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
[cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
[savebutton setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
[saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
[textfield setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
Actually this can be fixed manually by detecting the system version. Here is the right way to do this in this post
Try this code, it will work.
- (IBAction)showAlert:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc] init];
alertView.delegate = self;
alertView.title = #"Item?";
alertView.message = nil;
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView addButtonWithTitle:#"Cancel"];
[alertView addButtonWithTitle:#"Add another"];
[alertView addButtonWithTitle:#"Done"];
[alertView show];
}

UIPickerView not scrolling in actionSheet

I've added an UIPickerView into a UIActionSheet. Everything ok, but my picker can't be scrolled to choose a value. Any suggestions?
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
UIPickerView * picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 270)];
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
[actionSheet addSubview:picker];
[picker release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 500)];
[actionSheet release];
Best regards,
Dorin
An alternative solution to what you're trying to achieve is to set text field's inputView and inputAccessoryView. Setting these will replace the standard keyboard and bring in custom views. This includes the picker view. I happened to write a short example in this question here. Take a look and see if it helps.

Resources