How can I create a custom popup window for iPhone?

早过忘川 提交于 2019-12-04 02:44:12

The best way to do this is using a UIActionSheet. The code is here:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Facebook",@"Twitter", nil];
[actionSheet showInView:self.view];

A UIActionSheet comes from the bottom to the top with a certain number of buttons you wish to display. You can also put a cancel button that will automatically dismiss the UIActionSheet.

Here is how it will look like:

You should try third party classes for custom popup windows. Some of are as follow

1.) CMPopTipView
2.) KBPopupBubble
3.) ADPopupView

Jitendra

Used third party control, to do this.

Here is the Link you may download this project.

There are many way available. I would do this code personally:

// create view popup
UIView *viewPopup = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
[self.view addSubview:viewPopup];

// create Image View with image back (your blue cloud)
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
UIImage *image =  [UIImage imageNamed:[NSString stringWithFormat:@"myImage.png"]];
[imageView setImage:image];
[viewPopup addSubview:imageView];

// create button into viewPopup
UIButton *buttonTakePhoto = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
[viewPopup addSubview: buttonTakePhoto];
[buttonTakePhoto setTitle:@"Take Photo" forState:UIControlStateNormal];
[buttonTakePhoto addTarget:self action:@selector(actionTakePhoto) forControlEvents:UIControlEventTouchDown];
[viewPopup addSubview:buttonTakePhoto];

You can animated the Alpha viewPopup when click on the Icon Camera such as enable/disable the viewPopup.

The easiest way to implement what you are asking would be to create a view that looks how you want and contains the appropriate UIButtons and then add it as a subview (and animating it's appearance how you want) when the camera button is pressed. Although the comment on your question from Fonix is correct in that action sheets are designed to be used for this purpose on iOS.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!