怎么创建微信小游戏的授权按钮?

  • Creator 版本:2.0.8

  • 目标平台: 微信小游戏

  • 详细报错信息,包含调用堆栈:

  • 重现方式:

  • 之前哪个版本是正常的 :

  • 手机型号 :iPhone 7 P、

  • 手机浏览器 :

  • 编辑器操作系统 :

  • 编辑器之前是否有其它报错 :

  • 出现概率:

  • 额外线索:

请问怎么创建小游戏的微信授权按钮?呢,js里面绑定的按钮的背景图片怎么显示到创建的授权按钮上??

wx.createUserInfoButton({
type: ‘text’,
text: ‘获取用户信息’,
style: {
left: 10,
top: 76,
width: 200,
height: 40,
lineHeight: 40,
backgroundColor: ‘#ff0000’,
color: ‘#ffffff’,
textAlign: ‘center’,
fontSize: 16,
borderRadius: 4
}
})
button.onTap((res) => {
console.log(res)
})

把按钮设为透明,放到相应按钮上

1赞

大佬们,怎么做呢?请求高手兄指导!

你这个是创建的微信的授权按钮,但是它怎么放到相应的按钮上呢?

获取相应按钮宽高坐标,转给授权按钮,授权按钮设为透明,怎么实现。。。我也正在尝试中,还没成功;

好吧,一起来实现吧

private createAuthorizeBtn(btnNode:cc.Node) {
let btnSize = cc.size(btnNode.width+10,btnNode.height+10);
let frameSize = cc.view.getFrameSize();
let winSize = cc.director.getWinSize();
// console.log("winSize: ",winSize);
// console.log("frameSize: ",frameSize);
//适配不同机型来创建微信授权按钮
let left = (winSize.width0.5+btnNode.x-btnSize.width0.5)/winSize.widthframeSize.width;
let top = (winSize.height
0.5-btnNode.y-btnSize.height0.5)/winSize.heightframeSize.height;
let width = btnSize.width/winSize.widthframeSize.width;
let height = btnSize.height/winSize.height
frameSize.height;
// console.log("button pos: ",cc.v2(left,top));
// console.log("button size: ",cc.size(width,height));

let self = this;
self.btnAuthorize = wx.createUserInfoButton({
    type: 'text',
    text: '',
    style: {
        left: left,
        top: top,
        width: width,
        height: height,
        lineHeight: 0,
        backgroundColor: '',
        color: '#ffffff',
        textAlign: 'center',
        fontSize: 16,
        borderRadius: 4
    }
})

self.btnAuthorize.onTap((uinfo) => {
    console.log("onTap uinfo: ",uinfo);
    if (uinfo.userInfo) {
        console.log("wxLogin auth success");
        wx.showToast({title:"授权成功"});
    }else {
        console.log("wxLogin auth fail");
        wx.showToast({title:"授权失败"});
    }
});

}

看这个帖子: https://forum.cocos.com/t/wx-createuserinfobutton/60207/8

我已经成功,和这代码差不多,只不过要根据自己的适配去获取相应按钮坐标。