I need some modal view on iPhone app where I will display few labels, one UIImageView and two buttons. Design needs to be whole custom.
Is this custom UIAlertView? How to make something similar?
There is a nice blog post by Jeff LaMarche about how to create a custom Alert View. You can take inspiration from there.
http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
** UPDATE on April 24, 2017 **
Unfortunately the blog doesn't exist anymore. However you can retrieve the post from the Web Archive:
https://web.archive.org/web/20160430051146/http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
See the source for Tapku library. They have this option - you can always hack/tweak source code for it. Its not that difficult though, Just a lot of layer magic going around (e.g. the vignette effect). and most of the assets are images. You just need to break it down properly.
You can acquire that simply following the following steps
Create UIview (ViewA)of size 320*480 , so that it will cover whole screen of iPhone with background set to clearColor.This will serve as super view for our purpose;
Create another UIView (ViewB) of size 320*480 with background color set to black and opacity to 40%.
3.Now you can add any view on ViewB.
Now add ViewB to ViewA.
Finally you can Present this view where ever required. The effect will be, ViewA will cover the Background viewController, ViewB will server as suppressing effect for background view controller and views on B are the UIElement you will see.
Making a view like this is simple. You just need to create a custom view with the pieces that you want and just make it hidden or set the alpha to 0.0. Then un-hide it when you want to use it.
To prevent interaction with other items behind the view put a blank semi-transparent view right behind your custom view.
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"\n\Please wait. \n Authorising Credentials..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"smile.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];
[alert addSubview:imageView];
[imageView release];
[alert addButtonWithTitle:#"Cancel"];
[alert show];
Related
I was wondering how to create and customize a UIAlert View Popup, like ones in popular games such as Angry Birds or Cut the Rope.
I just want to say can you please rate my game and have 3 options to choose from. I want to design it so the text font and color changes and the background color can change to a picture or something? Thanks in Advance! :)
If your UIAlert is short enough to fit without the inherent scroll bar of longer text, then this will work:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title Here" message:#Message here..." delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
((UILabel*)[[alert subviews] objectAtIndex:1]).textAlignment = UITextAlignmentLeft;
((UILabel*)[[alert subviews] objectAtIndex:1]).font = [UIFont systemFontOfSize:12];
[alert show];
You should try subclassing UIAlertView using this tutorial. Such UIAlertViews can be achieved with either a subclass of UIAlertView or by creating a separate view all together that simulates the look and feel of a UIAlertView.
I have this code:
JMenuController *menuController = [[JMenuController alloc] init];
NSArray *buttonsArray = [NSArray arrayWithObjects:#"From Libary", #"Take Photo or Video", nil];
[menuController showMenuWithTitle:#"Add Media" ButtonTitles:buttonsArray animated:YES];
self.currentMenuType = JCreateMenuTypeNewMedia;
[[[[UIApplication sharedApplication] delegate] window] addSubview:menuController];
The problem is, the view appears below the keyboard, which is already on screen. How do i fix this?
The easiest way to display some view on top of the keyboard is put that view inside a UIWindow for which you set the windowLevel property to UIWindowLevelAlert. Something like:
UIView *myView = [[UIView alloc] initWithFrame:rect];
UIWindow *myWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
myWindow.windowLevel = UIWindowLevelAlert;
[myWindow addSubview:myView];
[myWindow makeKeyAndVisible];
If you're using ARC, make sure you keep a strong reference to myWindow. Otherwise, it'll get automatically released and so it won't get added to your application windows.
(This is how UIActionSheet and UIAlertView work internally. When one of them is visible, have a look at [UIApplication sharedApplication].windows and you'll see they create windows with their windowLevel set to UIWindowLevelAlert.)
Ok it took awhile for me to understand what you wanted to do. You have 2 options.
Resign the keyboard and show the view with the buttons.
Use a UIActionSheet to display the buttons over the keyboard like it does in the Messages application when you press the camera to send a picture to someone.
I would recommend the later.
Edit:
Take a look at this for your custom UIActionSheet Show a view over the keyboard
The keyboard exists in its own window. To put things over it, you either have to put things into the keyboard's window (this is not a supported behavior), or create yet another window and put it over the keyboard.
I would like to add a bunch of UILabels or NSStrings to the UIALertView since I have run out of space on my display.
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle:#"random" message:nil delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles: nil];
//firstString=[[UILabel alloc]initWithFrame: CGRectMake(12.0, 70.0, 260.0, 25.0)];
[alertDialog addSubview:firstString];
[alertDialog show];
[alertDialog release];
I can tell you from experience that this is a bad idea. In earlier version or iOS there were tricks using undocumented behavior, Apple made changes to the underlaying code and it all broke badly. Just create a UIView the way you like. If you want to dim the rest of the screen just place a semi-transparenr view over the screen and under your view.
You can use a alternative implementation of an alert view. One, that is not a subclass of UIAlertView — so it is absolutely independent to any changes Apple may release. And you have the possibility to add any subview as a clean property.
TSAlertView is such an alternative implementation.
you can use uitextfield to do so ,
simply change textcolor to while , and change background color to clearColor
I want to show a UIActionSheet in the middle of the screen.I tried with the following code
UIView *placeholderview=[[UIView alloc]initWithFrame:CGRectMake(0, 310, 320, 100)];
[self.view addSubview:placeholderview];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Open File",#"Save FIle",#"New File",#"Export Image",nil];
[actionSheet showFromRect:CGRectMake(0,0, 320, 10) inView:placeholderview animated:YES];
[actionSheet release];
I get the result as desired but i can click only cancel button, and the half of export image button.I don't know where i am going wrong.Kindly please any body help me.What should i do to make it working.
UIActionSheet is designed to be presented from the bottom of the screen.
It provides methods for presenting from a toolbar or tab bar in cases where those UI elements may cause obstruction.
Why are you wanting to show the action sheet in the middle of the screen. I wouldn't recommend this because it looks wrong, and isn't the designed behaviour of the control.
The method you are currently using is for iPad - it shouldn't be used on iPhone, as it causes undefined behaviour (as you are experiencing).
UIActionSheet's showFromRect:inView:animated: method is only supposed to be used on iPad. Its behavior on iPhone is undefined.
I am using a standard pop up action in my iphone app (the pop up at the bottom of the screen). This has 2 buttons "ok" and "cancel". It seems the standard colour scheme is to have the top button red. I want to change this so the top button is green. I have been googling forever and can't find the solution. Any ideas would be great. Thanks
You can browse through ActionSheet ( I assume you use UIActionSheet class) subviews - like that:
NSArray* subViews = [aSheet subviews];
for (UIView* sView in subViews)
{
...
}
And change subviews properties there as you like.
You can also create UIActionSheet without any buttons at all:
UIActionSheet* aSheet = [[UIActionSheet alloc] initWithTitle:#"\n\n\n" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
And afterward create your own custom buttons and add them to the ActionSheet view. (put more \n to the title to enlarge Sheet height)
I assume you're referring to a UIActionSheet. In a UIActionSheet, you can define a button that cancels the action and has a black background, a button that marks a destructive action and has a red background, and all other buttons which have white backgrounds. Which option corresponds to which class of actions can be specified in the initialization of the UIActionSheet using – initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:.
The design of a UIActionSheet, including why you should only use these colors for your buttons, is explained in the iPhone Human Interface Guidelines. I'd follow Apple's suggestions in this regard, as they will make your application easier to use.
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:#""
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil,#"Mail",#"Facebook",#"Twitter",nil
otherButtonTitles:nil];
NSArray *buttons = [action subviews];