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

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Flutter中使用友盟分享,首先需要在项目中添加友盟分享的插件。可以使用flutter_umeng_share插件,它提供了友盟分享的各种功能。 1. 在pubspec.yaml文件中添加依赖: ``` dependencies: flutter_umeng_share: ^2.0.0 ``` 2. 在项目中集成友盟分享SDK: 在Flutter项目的MainActivity.java文件中,添加以下代码: ``` import com.umeng.socialize.UMShareAPI; public class MainActivity extends FlutterActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GeneratedPluginRegistrant.registerWith(this); UMShareAPI.get(this);//添加这一行 } } ``` 3. 初始化友盟分享SDK: 在项目中的main.dart文件中,添加以下代码: ``` import 'package:flutter_umeng_share/flutter_umeng_share.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await FlutterUmengShare.init( androidKey: 'your_umeng_android_app_key', iosKey: 'your_umeng_ios_app_key'); runApp(MyApp()); } ``` 其中,'your_umeng_android_app_key'和'your_umeng_ios_app_key'需要替换为你自己的友盟App Key。 4. 使用友盟分享: ``` import 'package:flutter_umeng_share/flutter_umeng_share.dart'; //分享文本 FlutterUmengShare.shareText('This is a test.'); //分享图片 FlutterUmengShare.shareImage(imagePath: 'image_path', text: 'This is a test.'); //分享链接 FlutterUmengShare.shareWeb( url: 'https://www.example.com', title: 'This is a test.', description: 'This is a test.', thumb: 'thumb_image_path'); ``` 以上就是在Flutter中使用友盟分享的基本步骤。你可以根据自己的需求,选择更多的分享方式,例如分享音乐、视频等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值