UIAlertView in landscape mode does not display message [duplicate] - uialertview

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UIAlertView not showing message text
I am trying to create a simple UIAlertView for an app in landscape mode but all I see is the title and buttons but no actual message.
It has something to do with the space available for the UIAlertView on the screen as if I remove a couple of the buttons then the message displays fine.
Is there a way to force the UIAlertView to resize itself to fit?
Relevant code is here
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Free Update",nil)
message:NSLocalizedString(#"There is a new version of this app available in the App Store. Download it now.",nil)
delegate:self
cancelButtonTitle:NSLocalizedString(#"Don't remind me",nil)
otherButtonTitles:NSLocalizedString(#"Download",nil), NSLocalizedString(#"Remind me later", nil), nil];
[alert show];
[alert release];
And this is the result:

a bit dirty but it works :o) just add a UILabel to the UIAlertView
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake( alert.frame.origin.x + 10, 16, 260, 70)];
messageLabel.backgroundColor = [UIColor clearColor];
messageLabel.text = #"Your message";
messageLabel.textColor = [UIColor whiteColor];
messageLabel.lineBreakMode = UILineBreakModeWordWrap;
messageLabel.numberOfLines = 2;
messageLabel.font = [UIFont systemFontOfSize:12];
messageLabel.textAlignment = UITextAlignmentCenter;
[alert addSubview:messageLabel];
another dirty hack to get more space between title and buttons.
- (void)willPresentAlertView:(UIAlertView *)alertView {
float moreSpace = 20.0f;
alertView.frame = CGRectMake(alertView.frame.origin.x, alertView.frame.origin.y - moreSpace
,alertView.frame.size.width, alertView.frame.size.height + moreSpace*2 + 10.0f);
for ( UIView *view in [alertView subviews] ) {
if ( (view.class != UILabel.class ) && ( view.class != UIImageView.class ) ) {
[view setTransform:CGAffineTransformMakeTranslation(0, moreSpace * 2)];
}
}
}

In the end we had to drop one of the buttons from the alert view to make it work in landscape mode.

Related

UIAlertView title label strange background color issue

First I show the UIAlertView like this in my view controller (really nothing fancy at all):
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Thank you"
message:#"Successfully saved bookmark"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
But as you can see in the screenshot, the title label is taking the background of my view as its background color:
I have not even the slightest idea of where this could come from, here is how I style my view controller when it appears:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = #"Details";
[self.view styleBackgroundColor];
[self.saveToBookmarks configureButtonStyle];
[self.getDirections configureButtonStyle];
self.name.text = [simoItem name];
self.relativeLocation.text = [self relativeLocationStringForLocation:[simoItem location]];
self.address.text = [simoItem address];
self.type.text = [self buildTypesString];
[self.name styleMainLabel];
[self.address styleSubLabel];
[self.type styleSubLabel];
[self.relativeLocation styleSubLabel];
}
Tried cleaning the project, uninstalling the app from the sim and shaking my computer but nothing has done it so far...
EDIT: added code for styleMainLabel on request
-(void) styleMainLabel {
//colors
UIColor *backgroundColor = [Utilities getBackgoundColorPreference];
UIColor *textColor = [Utilities getTextColorPreference];
[self setBackgroundColor:backgroundColor];
[self setTextColor:textColor];
//text size styling
self.font = [UIFont fontWithName:#"Tiresias PCfont" size:35.0];
self.adjustsFontSizeToFitWidth = YES;
}
Okay I fixed the problem, this was cause by some CALayer color properties set in accessibility events callbacks. Here is the code that causes the problem
- (void)accessibilityElementDidBecomeFocused {
[super accessibilityElementDidBecomeFocused];
CALayer *layer = [self layer];
layer.backgroundColor = [[Utilities getFocusedBackgroundColorPreference] CGColor];
}
-(void) accessibilityElementDidLoseFocus {
[super accessibilityElementDidLoseFocus];
CALayer *layer = [self layer];
layer.backgroundColor = [[Utilities getBackgoundColorPreference] CGColor];
}
I haven't fixed it yet but turning off accessibility made it disappear. Thanks for your help.
There may be problem in styleMainLabel code. So first check your code and again if you are getting then do it.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Thank you"
message:#"Successfully saved bookmark"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
UILabel *theTitle = [alert valueForKey:#"_titleLabel"];
[theTitle setBackgroundColor:[UIColor clearColor]];

How to put uitextfield for user id and password in UIAlertView?

I am creating an application where i need to create two UITextField or TextBox for User id and password inside a UIAlertView for User login.I have tried something but here the textfield created becomes very big and almost cover the whole alert view.Please somebody help me how to organize the textfield and labels etc inside the alert view. I need like - there should be a small textfield against the label "User Id" and "Password". So how to do that? please help me. Thanx in advance.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"User Login" message:#"Please Enter the Following \n\n\n\n\n\n\n" delegate:self cancelButtonTitle:#"Close" otherButtonTitles:#"Sign In", nil];
UILabel *lblUserName = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, 85, 21)];
lblUserName.tag =2;
//lblUserName.backgroundColor = [UIColor darkGrayColor];
lblUserName.font = [UIFont systemFontOfSize:15.0];
lblUserName.text = #"User Name:";
lblUserName.textColor=[UIColor whiteColor];
//[lblUserName setFont:[UIFont fontWithName:#"TimesNewRomanPS-boldMT" size:8]];
lblUserName.backgroundColor = [UIColor clearColor];
[alert addSubview:lblUserName];
UITextField *txtUserName;
//if(txtUserName==nil)
txtUserName = [[UITextField alloc] initWithFrame:CGRectMake(89, 50, 160, 30)];
txtUserName.tag = 3;
txtUserName.borderStyle = UITextBorderStyleBezel;
txtUserName.textColor = [UIColor whiteColor];
txtUserName.font = [UIFont systemFontOfSize:12.0];
txtUserName.placeholder = #"User ID";
[alert addSubview:txtUserName];
alert.tag=3;
[alert show];
[alert release];
As of iOS5, UIAlertView supports a login screen using the Alert Style UIAlertViewStyleLoginAndPasswordInput.
More information in the UIAlertView Class Reference
UIAlertView *alert =[UIAlertView alloc] init];
alert.delegate =self //make sure to add the UIAertViewDelegate in the .h file
alert.alertViewStyle =UIAlertViewStyleLoginAndPasswordInput;
alert.message =#"Please login";
[alert show];
[alert release];
Then in the clickedButtonAtIndex delegate method:
{
UITextField *username = [alertView textFieldAtIndex:0];
UITextfield *password = [alertView textFieldAtIndex:1];
NSLog(#"Username %"# password %"#,username.text, password.text);
}

I want to display UIProgressView on UIAlertView

I want to display UIProgressView on UIAlertView for displaying the processing of uploading of the file. But I have searched too much and also find on that link but sill unable to do that. I don't get idea from this
If anyone know the easiest way to do that then please let me know.
I've had problems doing this, and ended up with this:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
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]];
[av setValue:progressView forKey:#"accessoryView"];
[av show];
Try this code...
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(20, 20, 200, 15);
pv.progress = 0.5;
[av addSubview:pv];
[av show];
While this doesn't quite answer your question, try MBProgressHud, a third-party control that has this feature built-in. The examples supplied on Github should get you up to speed pretty quickly.
Try this code. Put YES for activity indicator and NO for progressView
- (void) createProgressionAlertWithMessage:(NSString *)message withActivity:(BOOL)activity
{
progressAlert = [[UIAlertView alloc] initWithTitle: message
message: #"Please wait..."
delegate: self
cancelButtonTitle: nil
otherButtonTitles: nil];
// Create the progress bar and add it to the alert
if (activity) {
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f);
[progressAlert addSubview:activityView];
[activityView startAnimating];
} else {
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)];
[progressAlert addSubview:progressView];
[progressView setProgressViewStyle: UIProgressViewStyleBar];
}
[progressAlert show];
[progressAlert release];
}
Why not make use of the alerviewdelegate method
- (void)willPresentAlertView:(UIAlertView *)alertView
The advantage of this is we can see what size the alertview will actually be on screen, as iOS has precomputed this at this point, so no need for magic numbers - or overriding the class which Apple warn against !
And as of iOS7 I remember reading some document from Apple saying not to hard code any frame sizes but to always compute them from the app, or something along those lines ?
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGRect alertRect = alertview.bounds;
UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT);
// Do what ever you want here to set up the alertview, as you have all the details you need
// Note the status Bar will always be there, haven't found a way of hiding it yet
// Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h>
objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview
}
To pull reference to the loading bar in
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Then use
UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey);
Remember to have defined
#import <objc/runtime.h>
static char myKey;
At the top of your class declaration
This is create a alert view
UIAlertController* alert=[UIAlertController alertControllerWithTitle:#"Message" message:#"This is test" preferredStyle:UIAlertControllerStyleAlert];
now add textfield
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder=#"Enter Text label";
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.backgroundColor=[UIColor whiteColor];
}];
and added it on view
[self presentViewController:alert animated:YES completion:nil];

UITextView large text in UIAlertView

I have an UIAlertView with UITextView.
on ViewDidAppear I do [textView setText:] with a large text, but the alert shows an empty textView, and only after I touch the textView to scroll, the text appears.
What should I do in order to make the text appear in the textView in the alert, without scrolling it to "refresh" it?
Thanks!
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
av = [[UIAlertView alloc]initWithTitle:#"Terms of Service" message:#"\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:#"Disagree" otherButtonTitles:#"Agree",nil];
UITextView *myTextView = [[UITextView alloc] initWithFrame:CGRectMake(12, 50, 260, 142)];
[myTextView setTextAlignment:UITextAlignmentCenter];
[myTextView setEditable:NO];
myTextView.layer.borderWidth = 2.0f;
myTextView.layer.borderColor = [[UIColor darkGrayColor] CGColor];
myTextView.layer.cornerRadius = 13;
myTextView.clipsToBounds = YES ;
[myTextView setText:#"LONG LONG TEXT"];
[av addSubview:myTextView];
[myTextView release];
[av setTag:1];
[av show];
}
This is because you have initially set message as #"\n\n\n\n\n\n\n" for UIAlertView. Set your UITextView first and then set UIAlertView's message as textView's text.
Add \n characters in place of message in alert view . Then create a UILabel add add to alert view. Like this
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:#"%#\n\n\n", #"Title"] message:#"\n" delegate:self cancelButtonTitle:NEVER_DISPLAY_BUTTON_TEXT otherButtonTitles:nil];
[alert addButtonWithTitle:#"Text"];
[alert addButtonWithTitle:#"Text"];
[alert addButtonWithTitle:#"Text"];
[alert addButtonWithTitle:#"Text"];
[alert show];
newTitle = [[UILabel alloc] initWithFrame:CGRectMake(10,-55,252,230)];
newTitle.numberOfLines = 0;
newTitle.font = [UIFont systemFontOfSize:15];
newTitle.textAlignment = UITextAlignmentCenter;
newTitle.backgroundColor = [UIColor clearColor];
newTitle.textColor = [UIColor whiteColor];
newTitle.text = [NSString stringWithFormat:#"%#",self.message];
[alert addSubview:newTitle];
You might need to adjust size of Uilable to match in your alert view.
Try with this:
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"Terms of Service"
message:[NSString stringWithFormat:#"%# \n\n\n",myTextView.text]
delegate:self
cancelButtonTitle:#"Disagree"
otherButtonTitles:#"Agree",nil
];

how to call a function as user click on search in alert view iphone

//---------Searchoing----- //
- (IBAction) Search_hadit
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Search"
message:#" "
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Search",
nil];
CGRect frame = CGRectMake(14, 35, 255, 23);
myTextField = [[UITextField alloc] initWithFrame:frame];
myTextField.borderStyle = UITextBorderStyleBezel;
myTextField.textColor = [UIColor blackColor];
myTextField.textAlignment = UITextAlignmentCenter;
myTextField.font = [UIFont systemFontOfSize:14.0];
myTextField.placeholder = #"Enter Query";
myTextField.backgroundColor = [UIColor whiteColor];
myTextField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
myTextField.keyboardType = UIKeyboardTypeDefault;// use the default type input method (entire keyboard)
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.delegate = self;
myTextField.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
[alert addSubview:myTextField];
[alert show];
[alert release];
}
When I click search button in my app alert view show...
I want when user click search button I get the text which he enter and send this data to another function on as he click search button where I can perform search. Any idea?
I guess (acording to the title) you'll need an UIAlertViewDelegate or at least the function:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString* buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle equalToString:#"Search"]) {
[do something];
}
}
But the text in your description describes a different problem than your title. I can't provide a solution to that, though.