My UIActionSheet is transparent when it displays. How do I change this? here's a screenshot of what the problem looks like:
the code:
- (IBAction)btnTakePicture_Clicked:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..." delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Camera", #"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
actionSheet.tag = 1;
[actionSheet showInView:self.view];
UIButton *btn = (UIButton *)sender;
intButton = btn.tag;
}
I believe what's causing problems is
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
Probably in iOS 7 this causes the transparency. Try removing it.
Also you are setting the alpha to 0.9, which will cause some transparency in any case (not as showed in the screenshot though). If you want a completely opaque action sheet, remove also
actionSheet.alpha=0.90;
Removing the lines:
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
Should do the trick
Related
I want to create action sheet with two buttons, but i want the buttons to have thumbnail icons, is that possible? any other solutions? maybe there is a way to customize the action sheet buttons.. like to design them separately?
this is my current action sheet method:
- (void)tapResponder {
NSLog(#"Tap!");
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"this is a title"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"one", #"two", nil];
[actionSheet showInView:self.view];
}
but i really like to stay with ios design so please give me a cool solution :))
thankssss!
Maybe this helps:
for (UIView *subview in actionSheet.subviews) {
if( [subview isKindOfClass: [UIButton class]] ){
UIButton* btn = (UIButton*) subview;
[btn setImage:[UIImage imageNamed: #"imageName"] forState:UIControlStateNormal];
}
}
Very possible, very easy to implement :
This works with the new UIAlertController as well :
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerSytleActionSheet];
//Add your Actions
...
UIAlertAction *snapshot = [UIAlertAction actionWithTitle:#"Snapshot" style:UIAlertActionSytleDefault handler:^(UIAlertAction *action) {
}
//create a UIImage to display since it's technically a tableView:
UIImage *snapshotImage = [UIImage imageNamed:#"snapshot.png"];
//add it to the UIAlertAction of your choosing
[snapshot setValue:snapshotImage forKey:#"image"];
...
[alertC addAction:snapshot];
[self presentViewController:alertC animated:YES completion:nil];
Prior to iOS 8 it can be done this way:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"this is a title"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"one", #"two", nil];
[[[action valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"yourImage.png"] forState:UIControlStateNormal];
[[[action valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"yourImage_Highlighted.png"] forState:UIControlStateHighlighted];
[actionSheet showInView:self.view];
A couple of notes about this, make sure you properly size your image, whatever the H x W demensions are is how huge the row will become once it's inserted into the Action Sheet. So use something like 30x30. Also, whatever color your image is will default to the blue tint. Additionally, this isn't considered public API, apps do get approved this way, but you do run the risk
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:.
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];
Inside my viewDidLoad, I have the following:
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 1;
longpressGesture.allowableMovement = 5;
longpressGesture.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:longpressGesture];
[longpressGesture release];
I created the following:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Delete Record?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Yes",#"No",nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
Using the simulator, when I long press, two action sheet shows up instead of the one.
Any ideas as to why this is so?
Is it a problem with the simulator?
It's not a problem with the simulator.
The gesture handler is called multiple times as the gesture goes through different states (began, ended, etc).
You need to check the gesture's state in the handler method:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
if (sender.state == UIGestureRecognizerStateBegan)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] init...
[actionSheet showInView:self.view];
[actionSheet release];
}
}