1.做什么?
许多项目中,需要用到带箭头的弹出框框,比如菜单的选择等等。效果类似这样
2.如何做?
step1:在github下载并导入第三方文件:WBPopOverView.h WBPopOverView.m ;找不到可以留言,我发给你哦。
step2:popview的初始化,需要指点其箭头弹出的位置和箭头弹出的方向;弹出框view是WBPopOverView的backview属性,可以在上面add想要的内容。最后显示WBPopOverView用pop方法。
- (void)popViewWithPoint:(CGPoint)point andDirction:(WBArrowDirection)direction
{
self.popView = [[WBPopOverView alloc]initWithOrigin:point Width:200 Height:300 Direction:direction];
//这里是设置backView的颜色
self.popView.backView.backgroundColor = [UIColor blueColor];
//弹出框
[self.popView popView];
}
箭头的方向在有12个方向,在WBPopOverView.h中
typedef NS_ENUM(NSUInteger,WBArrowDirection){
//箭头位置
WBArrowDirectionLeft1=1,//左上
WBArrowDirectionLeft2,//左中
WBArrowDirectionLeft3,//左下
WBArrowDirectionRight1,//右上
WBArrowDirectionRight2,//右中
WBArrowDirectionRight3,//右下
WBArrowDirectionUp1,//上左
WBArrowDirectionUp2,//上中
WBArrowDirectionUp3,//上右
WBArrowDirectionDown1,//下左
WBArrowDirectionDown2,//下中
WBArrowDirectionDown3,//下右
};
以按钮1为例,指定箭头的位置是在按钮1的正下方中间,箭头的方向是在上方中央。
- (IBAction)button1clicked:(UIButton *)sender {
//设定箭头的位置
CGPoint point = CGPointMake(sender.frame.origin.x+sender.frame.size.width/2, sender.frame.origin.y+sender.frame.size.height);
//箭头的方向
[self popViewWithPoint:point andDirction:WBArrowDirectionUp1];
}