该弹窗控件有白色和黑色这两种风格, 使用方法也非常简单, 和系统的UIAlertController差不多的使用方法, 你只需要设置好对应的action和设定好弹窗箭头要指向的点(CGPoint)或者要指向的控件即可, 该弹窗控件会自动计算箭头指向和弹出位置
所有效果如下图:
该弹窗有两种风格:
白色风格: PopoverViewStyleDefault
(默认为此风格)
黑色风格: PopoverViewStyleDark
可以设置图片也可以不设置图片:objc - (IBAction)showWithoutImage:(UIButton *)sender { PopoverAction *action1 = [PopoverAction actionWithTitle:@"Title" handler:^(PopoverAction *action) { // 该Block不会导致内存泄露, Block内代码无需刻意去设置弱引用. }]; ... PopoverView *popoverView = [PopoverView popoverView]; popoverView.style = PopoverViewStyleDark; [popoverView showToView:sender withActions:@[action1, ...]]; }
也可以设置在弹出窗口时显示背景阴影层:objc - (IBAction)rightButtonAction:(UIButton *)sender { PopoverView *popoverView = [PopoverView popoverView]; popoverView.showShade = YES; // 显示阴影背景 [popoverView showToView:sender withActions:@[...]]; }
使用方法: (将PopoverView文件夹拖到你的项目中然后 #import "PopoverView.h"
)objc // 附带左边图标的 PopoverAction *action1 = [PopoverAction actionWithImage:Image title:@"Title" handler:^(PopoverAction *action) { // 该Block不会导致内存泄露, Block内代码无需刻意去设置弱引用. }]; // 纯标题的 PopoverAction *action1 = [PopoverAction actionWithTitle:@"Title" handler:^(PopoverAction *action) { // 该Block不会导致内存泄露, Block内代码无需刻意去设置弱引用. }]; ... PopoverView *popoverView = [PopoverView popoverView]; //popoverView.showShade = YES; // 显示阴影背景 //popoverView.style = PopoverViewStyleDark; // 设置为黑色风格 //popoverView.hideAfterTouchOutside = NO; // 点击外部时不允许隐藏 // 有两种显示方法 // 1. 显示在指定的控件 [popoverView showToView:sender withActions:@[action1, ...]]; // 2. 显示在指定的点(CGPoint), 该点的坐标是相对KeyWidnow的坐标. [popoverView showToPoint:CGPointMake(20, 64) withActions:@[action1, ...]];
PopoverView is available under the MIT license. See the LICENSE file for more info.