Action Sheet Button text alignment - ios

I am using actionsheet, and I have added unicode symbol. But my button title is not centered. I want the unicode symbol to be located at right most. If you think that it is impossible, can I use flag image separately rather than using unicode symbol ? If yes, how could I add image next to the button title?
UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:#"Would you like to see ozone cloud in your area or a trace of your walking/driving/biking activity" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"OzoneMap",#"ParticleMap", #"TraceMap \U0001F6A9", nil];
[[[actionsheet valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"play2.png"] forState:UIControlStateNormal];

Related

Why my UIActionSheet suddenly cutoff at the bottom of the device (iOS 8)?

I have some very standard code for UIActionSheet that works well on production.
-(void) showGameMenu
{
UIActionSheet * const activeSheet = [[UIActionSheet alloc] initWithTitle:#"Game"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"New Game", #"Save Game", #"Load Game", #"Email Game", #"Share Position", #"Setup Position", nil];
[activeSheet setTag:Framework::GameMenuButton];
[self showActionSheetOnToolbar:activeSheet];
}
-(void) showActionSheetOnToolbar:(UIActionSheet *)sheet
{
[sheet showFromBarButtonItem:_gameItem animated:YES];
}
_gameItem is not nil and is a proper UIBarButtonItem for the "Game" item as shown in the screenshot. The code has been working well on production until recently I tried to compile the same project with iOS 8 (it was compiled with iOS 7).
Suddenly, the menu got cut-off around the bottom edge of the device. Furthermore, there was a transparent black-thing covered about 3/4 of the screen horizontally.
I have no clue why this happens and not sure how to fix it.
Are you using auto-layout?
I am not sure but it can be about constraints.I say this because your "Game" and "Flip" buttons look smaller than what you expected.
So I recommend you to delete constraints on your view to your main view and add them again without checking "constrain to margins" via "pin" menu from bottom.
If this is not the case please add what you see in iOS 7.

Entering Text Using Pop-up in IOS 7

I have an app that was built on Xcode 4.6 and iOS 6. I am now upgrading it to iOS 7 using XCode 5.
I have this code that worked perfectly on iOS 6. What it does it bring a popup with UITextField in it. User can enter whatever text they want and hit OK. I take their text and put it in a UILabel.
The problem I have is that in iOS 7 when I bring up this pop-up text box, its not editable. Touching it doesn't do anything. How come?
Here is the code and screenshot
// ************
// ENTER TEXT
// ************
-(IBAction)insertText
{
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:#"Enter Text \n"
message:#"\n\n Keep it short and sweet"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
[dialog show];
}
Use the provided API instead this hack. Instead of adding your own text field (which was never actually supported), set the alert view's alertViewStyle to UIAlertViewStylePlainTextInput. This will give you a supported text entry field in the alert view.

Can i put multiple text boxes in an alert box in ios?

can I put multiple text input boxes on the alert box in iOS?
The best solution is to write or use a custom alert view that has the text fields that you need. If you only need 1 text field (or username/password) you can still use UIAlertView by setting the alertViewStyle property.
There are custom alert views already written, such as this one.
Yes, that's possible.
Just add UITextField as subviews to the UIAlertView.
Set the tag for each UITextField, in order to retrieve the entered text later.
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
textField1.tag=0;
textField1.borderStyle=UITextBorderStyleRoundedRect;
textField1.delegate=self;
[alert addSubview:textField1];
UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
textField2.tag=1;
textField2.delegate=self;
textField2.borderStyle=UITextBorderStyleRoundedRect;
[alert addSubview:textField2];
[alert show];
PLEASE NOTE that this is bad practice as it relies on UIAlertView being a subclass of UIView. As pointed out by MusiGenesis below, it won't work from iOS 7 onwards.
Hope that helps.
if you want 2 text boxes, you can use login style, but set second item secureTextEntry to NO, refer to
http://forums.macrumors.com/threads/uialertviews-with-textfields.1355954/

UIAlertView with 3 textfields and 3 labels overlap each other

I'm trying to create an UIAlertView with 3 TextFields and 3 Labels.
But with my current code they just go over each other, I've tried to change the frame of the AlertView and I've tried to use the CGAffineTransform but they both didn't work.
Here's my code:
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Sign in" message:#"\n\n\n\n\n" delegate:self cancelButtonTitle:#"Stop" otherButtonTitles:#"Sign in",nil];
UILabel *customerIdLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 55, 65, 21)];
customerIdLabel.tag =1;
customerIdLabel.text = #"Customer id: ";
[myAlertView customerIdLabel];
UITextField *customerIdField = [[UITextField alloc] initWithFrame:CGRectMake(89, 50, 160, 30)];
customerIdField.tag = 2;
customerIdField.placeholder = #"Fill in your customer id";
[myAlertView customerIdField];
And then there's two more combinations of those.
Here's the transform that I've tried:
CGAffineTransform myTransform = CGAffineTransformMakeScale(1.0, 0.5f);
[myAlertView setTransform:myTransform];
And this is what I get:
I'm pretty sure you aren't supposed to use UIAlertViews like that. You're supposed to set the title, message, etc and use the [alertview show]. The documentation seems to be pretty clear that it is an as-is class.The UIAlertViewStyle may be something you can look at, but the options are 1 text field, 1 secure field, or a username and password field.
Your best option is to use a new UIViewController and use the presentViewController:animated:completion: call.
I get around this by not changing UIAlertView but add a clear view on top of it when it is showing (you can pad with spaces) and add the textfields there at the correct location (note when rotation occurs). Then, let the tap go through the view to the UIAlertView. This has gone through Apple in 3 apps in the store.
Before the new SDK in xcode 5 you where able to add subviews to an alert view but that doesn't work anymore. I had to update an app because of that nasty code. Is better to use uipopovercontroller for ipad or show a UIView or even present a viewcontroller for either ipad or iphone.

ActionSheet not showing properly

I have this code to get NSStrings from an NSDictionary from an NSMutableArray but the problem is that it does not show right.
Here is the code:
UIActionSheet *playingSheet = [[UIActionSheet alloc] initWithTitle:#"Hi" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
for(NSDictionary *dict in accounts) {
NSString *name = [dict objectForKey:#"Name"];
[playingSheet addButtonWithTitle:name];
}
[playingSheet showInView:self.view];
[playingSheet release];
The problem is in my case, self.view is a subview of a parentView and is loaded from an XIB and is not full screen. So the problem is my action sheet is like half the width of the iPhone's screen and it is not even touching the bottom of the screen.
In my case, how would I fix it so its the top most view (so users can see it properly), and the way a regular actionSheet is supposed to look?
Thanks!
Edit: This was the fix:
[playingSheet showInView:[UIApplication sharedApplication].keyWindow];
You need to set the frame of the action sheet as
[playingSheet setFrame:CGRectMake(0, theHeightYouWant, 320, yourDesiredHeight)];
"theHeightYouWant" is the height by which you must shift the action-sheet upwards/downwards to put it in the right position on the screen. You can change this by trial and error. For example, if your self.view is in the lower half of the screen, "theHeightYouWant" will be negative!
Depending how your code is set up, you could try using self.parentViewController.view, self.view.window, self.view.superview, or any of a variety of things. You need to provide more information if you want a more detailed answer.

Resources