In my UIViewController <GLKViewDelegate> in need to make a simple text input when selecting a object.
Is there in UIKit a simple multiline text input popup ready to use ?
I already found UIAlertView with alertViewStyle=UIAlertViewStylePlainTextInput but it's only a simple line input.
thx
If you mean is there an equivalent of the text input UIAlertView with a UITextView rather than a UITextField, the answer is no.
Your question is not very clear. but I think UIActionSheet is what you need.
Edit
You can try this out
Set this in un .h file the the delegate like this
#interface NameOfYourClass : UIViewController <UIActionSheetDelegate>
And add this code in un .m File
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Action Sheet" delegate:self cancelButtonTitle:#"Cancel Button" destructiveButtonTitle:#"Destructive Button" otherButtonTitles:#"Other Button 1", #"Other Button 2", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
Edit2
So here's what to do to add a textfield to your allertview
UIAlertView *newAlert =[[UIAlertView alloc] initWithTitle:#"ADD item" message:#"Put it blank textfield will cover this" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
UITextField *newTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
newTextField.text=#"";
[newTextField setBackgroundColor:[UIColor whiteColor]];
[newTextField setKeyboardAppearance:UIKeyboardAppearanceAlert];
[newTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
[newTextField setTextAlignment:UITextAlignmentCenter];
[newAlert addSubview:newTextField];
[newAlert show];
Related
So the new iOS 7 has come out and I'm trying to add multiple textFields and labels to the UIAlertviews. I need three. I've been trying to add them as subviews and that doesn't work anymore. I have also tried to add multiple lines with the UIAlertViewStylePlainTextInput but it only seems to return one text field.
I need to add in labels to show them what to enter as well. Is there a way to accomplish this task with the new iOS 7?
The only solution i found using UIAlertView with more than one text field in iOS7 is for login only.
use this line to initialize your alertView
[alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
and this to grab the users input:
user = [alert textFieldAtIndex:0].text;
pw = [alert textFieldAtIndex:1].text
For other purposes than login view the other threads like this on: UIAlertView addSubview in iOS7
You can change accessoryView to any own customContentView in a standard alert view in iOS7
[alertView setValue:customContentView forKey:#"accessoryView"];
Note that you must call this before [alertView show].
Simplest illustrating example:
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"TEST" message:#"subview" delegate:nil cancelButtonTitle:#"NO" otherButtonTitles:#"YES", nil];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
v.backgroundColor = [UIColor yellowColor];
[av setValue:v forKey:#"accessoryView"];
[av show];
If you want to add just two textfields to your UIAlertView, you can use UIAlertViewStyleLoginAndPasswordInput and modify the textfields as follows:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Some Title" message:#"Some Message." delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:#"No, thanks", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert textFieldAtIndex:1].secureTextEntry = NO; //Will disable secure text entry for second textfield.
[alert textFieldAtIndex:0].placeholder = #"First Placeholder"; //Will replace "Username"
[alert textFieldAtIndex:1].placeholder = #"Second Placeholder"; //Will replace "Password"
[alert show];
Afterwards, in the UIAlertView delegate, you can simply get the text using:
text1 = [alert textFieldAtIndex:0].text;
text2 = [alert textFieldAtIndex:1].text;
I am creating an Alert view on click of a button. I have placed a UITextfield in it. But the Alertview is shifted upwards in the screen. I am not able to bring it back at the center of the screen.
Here is my code and Screenshot.
and the code for creating this Alert view is this:-
- (IBAction)btn_cancelAppointment_click:(id)sender
{
// Here We are Creating Alertview which asks for
UIAlertView* cancelAlert = [[UIAlertView alloc] init];
[cancelAlert setDelegate:self];
[cancelAlert setTitle:#"Are you sure you want to request cancellation of this appointment?"];
[cancelAlert setMessage:#" "];
[cancelAlert addButtonWithTitle:#"NO"];
[cancelAlert addButtonWithTitle:#"YES"];
UITextField * txt_cancelNote = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 88.0, 245.0, 30.0)];
[txt_cancelNote setBackgroundColor:[UIColor whiteColor]];
[txt_cancelNote setBorderStyle:UITextBorderStyleRoundedRect];
[txt_cancelNote setPlaceholder:#"Enter cancellation note"];
txt_cancelNote.tag = 11;
[cancelAlert addSubview:txt_cancelNote];
cancelAlert.delegate = self;
[cancelAlert show];
}
So, if somebody can tell me how to bring it back to the center of the screen. Any help will be highly appreciated.
Give a try by setting the transform property of the UIAlertView
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Test" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
alertView.transform = CGAffineTransformMakeTranslation(x, y);
I use the following code to show a UIAlertView with a text field:
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Rename", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField* textField = [alertView textFieldAtIndex:0];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
[alertView show];
The result looks like this on iOS 5.1:
and on iOS 6.1:
As you can see, the clear button is a bit higher than it should be on iOS 6.1. Any idea how to properly center the button? Adding textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; does not help either.
(Apparently, this is a bug in iOS 6.1 but maybe someone knows a workaround. Besides, the height of the text field in alert views also seem to differ in different OS versions but that is another issue.)
This looks like a bug from Apple, but you can always add your own clear button in the textField, doing something like this :
First create a UITextField property:
#property (nonatomic, strong) UITextField *textField;
And then assign it to the alertView's textField
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Rename", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
self.textField = [alertView textFieldAtIndex:0];
self.textField.delegate = self;
//Create a custom clear button
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 19, 19)];
[button setImage:[UIImage imageNamed:#"clearButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(clearText) forControlEvents:UIControlEventAllTouchEvents];
[self.textField setRightView:button];
self.textField.rightViewMode = UITextFieldViewModeAlways;
And then in the clearText method,
- (void)clearText {
[self.textField setText:#""];
}
I tried this out and it works
Hope this helps
Another way to do this is by overriding UITextField's clearButtonRectForBounds:.
I would like to show an alertview saying the process is in progress and would like to add the UIActivityIndicatorView inside the alertview to show the process is in progress, instead of outside the alertview. How do I do that? Any guidance will be helpful.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#" "Process in Progress..." " ];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];
[alert show];
I would rather suggest you to use MBProgressHud
and if u need to show some image and text then, use this
I know that there has been one question about this but it is not clear to me. I want to add a UISlider to UIAlertView. In the UIAlertView, I also add one UILabel to show the value of UISlider. What I have been done so far is:
UIAlertView *alert= [[UIAlertView alloc]
initWithTitle: #"Set delay"
message: #" "
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
UISlider *mySlider=[[UISlider alloc] initWithFrame:CGRectMake(20, 50, 200, 20)];
mySlider.maximumValue=10.00;
mySlider.minimumValue=1.00;
UILabel *myLabel=[[UILabel alloc] initWithFrame:CGRectMake(220, 50, 50, 40)];
int x=.........;//x should get value of mySlider
[myLabel setText:[NSString stringWithFormat:#"%d",x]];
[alert addSubview:myLabel];
[alert addSubview:mySlider];
[alert show];
[alert release];
so I want variable x to get value of mySlider and the myLabel will show the value of x. I get stuck at this point. Any suggestion is really appreciated.
Here what you need to do:
Make the UILabel global, that mean declare it on the header file (this is to reach the label easily).
Then add a target to the slider, with ValueChanged event.
[mySlider addTarget:self action:#selector(sliderHandler:) forControlEvents:UIControlEventValueChanged];
next, implement the sliderHandler method:
- (void) sliderHandler: (UISlider *)sender {
int x = sender.value;
[myLabel setText:[NSString stringWithFormat:#"value = %d",x]];
}
That will work with you.