• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

底部出一个半透明的View,类似友盟分享页面 (Swift 4)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

xib图解:


import UIKit


class ShareUMView: UITableViewCell {


    

    @IBOutlet weak var topView: UIView!

    @IBOutlet weak var bottomViewH: NSLayoutConstraint!

    @IBOutlet weak var shareTitleLabel: UILabel!

    @IBOutlet weak var contentViewbs: UIView!

    

    

    var titleArr: [String]! = []//["朋友圈", "微信", "QQ", "微博", "空间", "邀请卡"]

    var imageArr: [String]! = []//["share1", "share2", "share3", "share4", "share5", "share6"]

    

    override func awakeFromNib() {

        super.awakeFromNib()

        self.topView.addGestureRecognizer({

            return UITapGestureRecognizer.init(target: self, action: #selector(self.dismissAction(tap:)))

        }())

        self.contentView.backgroundColor = UIColor.black.withAlphaComponent(0.5)

    }


    

    func config(titles: [String], images: [String]) {

        self.titleArr = titles

        self.imageArr = images

        config()

    }

    

    private let topSpace: CGFloat = 12.0

    private let W =  UIScreen.main.bounds.width / 3

    private let H: CGFloat = CGFloat(75)

    func config() {

       

        var contentH: CGFloat = 0

        if imageArr.count % 3 > 0 {

            contentH = CGFloat(imageArr.count / 3 + 1) * (H + topSpace)

        } else {

            contentH = CGFloat(imageArr.count / 3) * (H + topSpace)

        }

        bottomViewH.constant = contentViewbs.frame.minY + contentH + 20

        

        for i in 0..<imageArr.count {

            let viewX = W * CGFloat(i % 3)

            let viewY = (topSpace + H) * CGFloat(i / 3)

            

            let containViewme = UIView(frame: CGRect.init(x: viewX, y: viewY, width: W, height: H))

            contentViewbs.addSubview(containViewme)

            

            let iv = UIImageView.init(frame: CGRect.init(x: (containViewme.frame.width - 50) / 2, y: 0, width: 50, height: 50))

            iv.image = UIImage.init(named: imageArr[i])

            iv.isUserInteractionEnabled = true

            containViewme.addSubview(iv)

            

            let label = UILabel.init(frame: CGRect.init(x: 0, y: iv.frame.maxY, width: containViewme.frame.width, height: 25))

            label.textAlignment = .center

            label.font = UIFont.init(name: "PingFang-SC-Medium", size: 13)

            label.textColor = UIColor.init(red: 140 / 255, green: 140 / 255, blue: 142 / 255, alpha: 1)

            label.text = self.titleArr[i]

            label.isUserInteractionEnabled = true

            containViewme.addSubview(label)

            

            let button = UIButton.init(frame: containViewme.bounds)

            button.setTitle(titleArr[i], for: .normal)

            button.setTitleColor(UIColor.clear, for: .normal)

            button.setTitleColor(UIColor.clear, for: .selected)

            button.addTarget(self, action: #selector(self.action(sender:)), for: .touchUpInside)

            containViewme.addSubview(button)

        }

        

    }

    

    var shareSuccessClosure:((String) -> Void)!

    @objc func action(sender: UIButton) {

        let titleStr = sender.currentTitle!

        print("titleStr---->\(titleStr)")

        //此处处理对应的分享

        self.removeFromSuperview()

        switch titleStr {

        case "朋友圈":

            break

        case "微信":

            break

        case "QQ":

            break

        case "微博":

            break

        case "空间":

            break

        case "邀请卡":

            break

        default:

            break

        }

        shareSuccessClosure(sender.currentTitle!)

    }

    

    @objc func dismissAction(tap: UITapGestureRecognizer) {

        self.removeFromSuperview()

    }

    

    override func setSelected(_ selected: Bool, animated: Bool) {

        super.setSelected(selected, animated: animated)


        // Configure the view for the selected state

    }

    

}


  

 //实际使用

        let shareV = Bundle.main.loadNibNamed("ShareAndGetView", owner: self, options: nil)?.first as! ShareAndGetView

        shareV.configData(frameCustom: self.view.bounds, imageStr: nil, getMoneyStr: nil, mark: 0)

        shareV.shareCloaure = {(shareStr) -> Void in

            let sharetoView = Bundle.main.loadNibNamed("ShareUMView", owner: self, options: nil)?.first as! ShareUMView

            

            sharetoView.config(titles: ["朋友圈", "微信", "QQ", "微博", "空间", "邀请卡"], images: ["share1", "share2", "share3", "share4", "share5", "share6"])

            sharetoView.shareSuccessClosure = {(titleStr) -> Void in

                print("分享页面的点击\(titleStr)")

        }

        self.view.addSubview(shareV)







鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Swift学习之类和结构体的创建发布时间:2022-07-13
下一篇:
[Swift]LeetCode314.二叉树的竖直遍历$BinaryTreeVerticalOrderTraversal发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap