我想为iPhone创建一个自定义弹出窗口,应该长这样:
在iPhone和iPod设备上实现这个功能的最正确方法是什么?
![enter image description here](https://istack.dev59.com/aOIg7.webp)
最好的方法是使用UIActionSheet。 代码在这里:
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Facebook",@"Twitter", nil];
[actionSheet showInView:self.view];
UIActionSheet会从底部向上弹出,显示一定数量的按钮。您还可以添加一个取消按钮,以自动关闭UIActionSheet。
这是它的样子:
UIActionSheet
现已被弃用,请立即使用UIAlertController
。请参见https://dev59.com/32445IYBdhLWcg3wM3bx#32295641。 - Suragch有许多方法可供选择。我个人会使用以下代码:
// 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];