how to resize alertview in iphone - iphone

Hi i want to show my alertview message on large font so user can read proper when i run but it show me as small only how to resie font of message according to ipad i try this but it not working for me what to in my code help me on this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"Flight Search" message:#"Please select both outbound and inbound flights" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
//UIAlertView* alert = [[[UIAlertView alloc] init]initWithFrame:CGRectMake(100,0,340,200)];// message:#"Please select both outbound and inbound flights" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
//[alert setTitle:#"Flight Search"];
//[alert setCenter:CGPointMake(160.0f, 240.0f)];
//alert.frame = CGRectMake( 100, 0, 600, 500 );
//[alert setNeedsLayout];
[alert show];
alert.frame = CGRectMake( 0, 0, 340, 200 );
//alert.frame = CGRectMake( 100, 0, 600, 250 );
[alert release];
}
else {
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"Flight Search" message:#"Please select both outbound and inbound flights" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}

From the UIAlertView docs:
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.
You can't modify it.
Check this question/response to find out how to make a custom alert view:

default UIALertView cannot be modified as per Apple's Documentation , Instead make your own Custom AlertView

UIAlertView have UITextView inside with two or single button. So that's why it can expends over vertically but not Horizontally according to input. If you need to expand it ,increase message contents but you r not able to change font size.

You can do any thing with the default alert view. It will re size according to the text you have written. if you want to, then you need to create your own custom alert view. Check the link. put custom image and buttons and then you will be able to re size it.

Related

LongPress on iPhone app opens 3 Alerts? AlertView or Gesture Code Issue [duplicate]

I created an application. Through developing it, i used long press button to show an alert.
This is my code:
- (IBAction)longPressDetected1:(UIGestureRecognizer *)sender {
// label1.text = #"Select Iran to observe its historical data projections ";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Press the blue button (+) to select your region "
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
Question: When I want to cancel the UIAlertView by using the cancelIbutton, I must press this button three times to cancel the UIAlertView. it means UIAlterview cannot be canceled just by one press.
Could you please help me?
The problem is that your are showing more than one alert view. Your long press handler will get called for different states.
From the docs for UILongPressGestureRecognizer:
Long-press gestures are continuous. The gesture begins (UIGestureRecognizerStateBegan) when the number of allowable fingers (numberOfTouchesRequired) have been pressed for the specified period (minimumPressDuration) and the touches do not move beyond the allowable range of movement (allowableMovement). The gesture recognizer transitions to the Change state whenever a finger moves, and it ends (UIGestureRecognizerStateEnded) when any of the fingers are lifted.
So you end up displaying an alert for the "Began" state, then the "Changed" state, and again for the "Ended" state. If you moved your finger around you would get a stream of "Changed" states and you would end up showing an alert for every one of them too.
You need to decide when you actually want the alert to appear. Do you want it to appear at the first "Changed" state or when the user lifts their finger and you get the "Ended" state.
Your code needs to be something like this:
- (IBAction)longPressDetected1:(UIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
// label1.text = #"Select Iran to observe its historical data projections ";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Press the blue button (+) to select your region "
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
This will show the alert when the user lifts their finger. Change UIGestureRecognizerStateEnded to UIGestureRecognizerStateChanged if you want the alert to appear as soon as the long press is recognized. But keep in mind you may still get multiples since a long press can generate multiple "Changed" states. In this case you need to add an additional check to only show the alert if there isn't already one.
Actually, here's an easy way to support a single alert on the "Changed" state:
- (IBAction)longPressDetected1:(UIGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateChanged) {
sender.enabled = NO; // Prevent any more state updates so you only get this one
sender.enabled = YES; // reenable the gesture recognizer for the next long press
// label1.text = #"Select Iran to observe its historical data projections ";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Press the blue button (+) to select your region "
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
Try this
- (IBAction)longPressDetected1:(UIGestureRecognizer *)sender {
// label1.text = #"Select Iran to observe its historical data projections ";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#""
message:#"Press the blue button (+) to select your region "
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
alert.tag =10;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (alertView.tag)
{
case 10:
if (buttonIndex==0)
{
}
break;
}
}
This is an old question, but I had a similar issue.
Any UILongPressGestureRecognizer will generate at least 4 changes of state:
changed - (i.e. changed to started)
began - (i.e. started)
changed - (i.e. changed to ended)
ended - (i.e. ended)
So to handle it well, you need to choose which of those conditions will activate an action.
The simplest, which sort of corresponds to 'touch up inside' for a UIButton is to detect the 'ended' state.
An example is below where 'longPress' is the instance of UILongPressGestureRecognizer
- (void)longPressedLastImage:(UILongPressGestureRecognizer*) longPress {
if (longPress.state == UIGestureRecognizerStateEnded) {
// do what you would in response to an equivalent button press
}
}
This lets you treat the continuous press more like the basic UIButton action.
'simple is better than complex' - T Peters - the Zen of Python

Setting the Frame of an Object Programatically Has No Effect

I need to me a UIAlertView viewer than the standard size.
This is what I'm trying so far:
UIAlertView *addNewDevice = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Add New Device", "Title for add new device") message:nil delegate:self cancelButtonTitle:NSLocalizedString(#"CANCEL", #"Cancel Button") otherButtonTitles:NSLocalizedString(#"OK", "OK"), nil];
addNewDevice.frame = CGRectMake(addNewDevice.frame.origin.x, addNewDevice.frame.origin.y, addNewDevice.frame.size.width, 500);
[addNewDevice show];
Yes I'm aware a width of 500 points is too big, but I merely put that value there to test and my UIAlertView is not modifying its size.
Admittedly I don't know much about dealing with objects programatically, but I have spent the afternoon reading about them with no luck regarding this. Any help will be appreciated.
Try putting the frame line after the show line.
[addNewDevice show];
addNewDevice.frame = CGRectMake(addNewDevice.frame.origin.x, addNewDevice.frame.origin.y, addNewDevice.frame.size.width, 500);

Can't get UIAlertView to work

I have a problem with UIAlertView i do not understand. I cannot get it to work. I have changed the code during test so the UIAlertView should hit directly when pressing the button.
I have tested with breakpoint/debugger and what is happening when i press the button is that the first line that it stops at is "otherButtonTitles:nil];".
I did test the piece of code in an other part of the app and it worked.
I have no idea what i am doing wrong.
- (IBAction)startNewGame_Button:(id)sender {
UIAlertView *noPlayersAlert = [[UIAlertView alloc] initWithTitle:#"VARNING"
message:#"Ingen spelare är vald!\n \n Välj spelare och försök igen!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[noPlayersAlert show];
[noPlayersAlert release];
...
}
==============UPDATE=====================
When i copy this code to another button it works??
Here it is in one line, tested that with the same result:
UIAlertView *noPlayersAlert = [[UIAlertView alloc] initWithTitle:#"VARNING" message:#"Ingen spelare är vald!\n \n Välj spelare och försök igen!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
==============UPDATE #2==================
Problem solved, even if i do not understand the reason, as i removed an "exit(0)" i had far below the UIAlertView during the testing.
Thanks to all of you who answered :)
Why have you not set the delegate to self?
How do you know the line stops at otherButtonTitles:nil? If there is a crash log, post the results of it.
You must set delegate a value, because it needs to call dissWith, delegate method of the alertView. So please set:
delegate: self

UIActionSheet long list behavior changed in 4.2?

I am seeing some changed behavior in iOS 4.2 with UIActionSheet. I can't find anything in Apple's developer docs or forums about it, so I'm not sure how to resolve it.
In my list app, I present the user with an actionsheet from which she can pick the list she wants to load on startup. Obviously that means there will be a variable number of items, and the control handles it fine. Until about 7 items, it shows all items as buttons. Once it crosses that threshold, it puts the items into a scroll view to choose from. Until 4.2, it included the Cancel button in that scrolling list. In 4.2, it now seems to be separating the Cancel control, leaving it as a button while putting the rest of the items into the scroll view. The problem is that it appears that it keeps the Cancel item in the list of button indices, so that when I inspect the buttonTitleAtIndex:buttonIndex in either clickedButtonAtIndex: or didDismissWithButtonIndex:, the first item returns "Cancel", then the other item titles are off by 1. Clicking the Cancel button also returns "Cancel".
Anyone else experienced this and have a suggestion for how to handle it? Again, this worked fine in 3.0, 3.1, 4.0, and 4.1.
Here's the relevant code I'm using:
- (IBAction)popupDefaultListActionSheet {
UIActionSheet *popup = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (List *l in allActiveLists) { // allActiveLists defined elsewhere
[popup addButtonWithTitle:[l label]];
}
popup.actionSheetStyle = UIActionSheetStyleBlackOpaque;
popup.tag = 23;
[popup becomeFirstResponder];
[popup showInView:[self.view.window.subviews objectAtIndex:0]];
[popup release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
DLOG(#"AppSettingsVC.actionSheet didDismissWithButtonIndex: %d", buttonIndex);
NSString *defaultListName = [actionSheet buttonTitleAtIndex:buttonIndex];
DLOG(#"chosen default list was: %#", defaultListName);
}
Try adding the cancel button dynamically at the end instead of setting it up initially:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"My Action Sheet"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (I32 i = 0; i < itemCount; i++) {
[actionSheet addButtonWithTitle:itemText];
}
[actionSheet addButtonWithTitle:#"Cancel"];
[actionSheet setCancelButtonIndex:itemCount];
Seems to work correctly in iOS 4.2 for us at least.

UIAlertView not displaying complete message

I have the following function to display error messages to user. But it does not seem to show the complete message. It will display upto certain characters followed by ....
How can I make it show the entire message?
(void) showAlert:(NSString*)title forMessage:(NSString*) body
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:body delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
There is a way.
When you present your alert, you can just implement this method:
- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(alertView.frame.origin.x, alertView.frame.origin.y -50
,alertView.frame.size.width, 300);
}
Adjust the height to fit your need. It will look something like this:
If you need to move the button around, you can just add new lines (\n) to your message, and it will move the button down.
As mentioned by sudo rm -rf, UIAlertView has a limit.
You can try creating your own "alert" that doesn't clip by creating a view controller and showing it using presentModalViewController:animated:.