如何为iPhone创建自定义弹出窗口?

Mai*_*r00 9 iphone cocoa-touch objective-c popup ios

我想为iPhone创建一个自定义弹出窗口,如下所示: 在此输入图像描述

为iPhone和iPod设备实现此功能的最正确方法是什么?

Abd*_*que 11

最好的方法是使用UIActionSheet.代码在这里:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Facebook",@"Twitter", nil];
[actionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)

UIActionSheet从底部到顶部,带有一定数量的按钮.您还可以放置一个取消按钮,该按钮将自动关闭UIActionSheet.

以下是它的样子:

在此输入图像描述


Bha*_*n_m 8

您应该尝试自定义弹出窗口的第三方类.一些如下

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


Jit*_*dra 6

使用第三方控件,执行此操作.

是您可以下载此项目的链接.


Ale*_*ano 5

有很多方法可供选择.我会亲自做这个代码:

// 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];
Run Code Online (Sandbox Code Playgroud)

单击图标相机(例如启用/禁用viewPopup)时,可以为Alpha viewPopup设置动画.