iOS 带箭头的弹出框

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];
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值