如何更改 FBSDKLoginButton iOS 8.3/Swift 1.2 的默认设计? [英] How can I change the default design of FBSDKLoginButton iOS 8.3/Swift 1.2?

查看:25
本文介绍了如何更改 FBSDKLoginButton iOS 8.3/Swift 1.2 的默认设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发应用程序,我需要更改 Facebook SDK 提供的 Facebook 按钮的默认设计.我成功地让提供的按钮透明并将其粘贴在设计的视图上方,并且效果很好(现在设计匹配并且 Facebook SDK 按钮的功能运行良好).这样做后我的问题出现了,因为按钮失去了它的 Ui 效果(点击时没有突出显示).请如果有人可以帮助我,我需要为这个设计的按钮添加高亮效果.让我们澄清一下:我已经将 UIView 设计为按钮,我在它上面放了一个透明的 Facebook SDK 按钮,结果是我的设计形状和 Facebook 按钮的功能同时存在,损失:点击时没有突出显示效果.

I'm working on App currently and I need to change the default design of Facebook button which is provided by Facebook SDK. I succeeded to let the provided button be transparent and stick it above over designed view , and it worked well(now the design is matched and the functionality of Facebook SDK button is working well). my problem turned up after I did that because the button lost it's Ui effects (no highlighting upon clicking). Please if any one can help me , I need to put highlighting effect to this designed button. Let clarify: I've UIView designed as button , I've put a transparent Facebook SDK button above it, the result is shape of my design and functionality of Facebook button at same time ,the loses : no highlighting effect upon clicking.

推荐答案

我已经尝试了以下代码,它以正确的方式提供了功能.但是我未能在单击按钮时为按钮提供突出显示效果.这是代码:

I've tried the following code , it gives the functionality in right manner.However I failed to give the highlighting effect to the button upon clicking on it. here is the code :

{
    if (FBSDKAccessToken.currentAccessToken() != nil)
        {
            // if user logged in then handleTap func will run instead of button functionality
            let tap = UITapGestureRecognizer(target: self, action: "handleTap:")
            self.btnSignUpwithFaceBook.addGestureRecognizer(tap)

        }

        else
        {
            let loginView : FBSDKLoginButton = FBSDKLoginButton()
            self.view.addSubview(loginView)
            loginView.center = self.btnSignUpwithFaceBook.center
            loginView.frame.size.width = self.btnSignUpwithFaceBook.frame.width
            loginView.frame.size.height = self.btnSignUpwithFaceBook.frame.height
            loginView.frame.origin.x = self.btnSignUpwithFaceBook.frame.origin.x
            loginView.frame.origin.y = self.btnSignUpwithFaceBook.frame.origin.y

            for subView in loginView.subviews
            {
                subView.removeFromSuperview()
            }
            loginView.layer.shadowColor = UIColor.clearColor().CGColor

            loginView.setBackgroundImage(nil, forState: UIControlState.Normal)
            loginView.setBackgroundImage(nil, forState: UIControlState.Application)
            loginView.setBackgroundImage(nil, forState: UIControlState.allZeros)
            loginView.setBackgroundImage(nil, forState: UIControlState.Highlighted)
            loginView.setBackgroundImage(nil, forState: UIControlState.Reserved)
            loginView.setBackgroundImage(nil, forState: UIControlState.Selected)

            loginView.setImage(nil, forState: UIControlState.Normal)
            loginView.setImage(nil, forState: UIControlState.Application)
            loginView.setImage(nil, forState: UIControlState.allZeros)
            loginView.setImage(nil, forState: UIControlState.Highlighted)
            loginView.setImage(nil, forState: UIControlState.Reserved)
            loginView.setImage(nil, forState: UIControlState.Selected)

            loginView.backgroundColor = UIColor.clearColor()
            // just for test
            self.btnSignUpwithFaceBook.layer.borderWidth = 1
            self.btnSignUpwithFaceBook.layer.borderColor = UIColor.whiteColor().CGColor
            loginView.layer.backgroundColor = UIColor.clearColor().CGColor

            loginView.readPermissions = ["public_profile", "email", "user_friends"]
            loginView.delegate = self
            loginView.setTranslatesAutoresizingMaskIntoConstraints(false)

            var constX = NSLayoutConstraint(item: loginView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.btnSignUpwithFaceBook, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
            view.addConstraint(constX)

            var constY = NSLayoutConstraint(item: loginView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.btnSignUpwithFaceBook, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)
            view.addConstraint(constY)

            let views = ["loginView": loginView]

            var constH = NSLayoutConstraint.constraintsWithVisualFormat("H:[loginView(57)]", options: NSLayoutFormatOptions(0), metrics: nil, views: views)
            view.addConstraints(constH)


            var constW = NSLayoutConstraint.constraintsWithVisualFormat("V:[loginView(281)]", options: NSLayoutFormatOptions(0), metrics: nil, views: views)

            view.addConstraints(constW)

}

实际上主要的问题是 facebookLogInButton 是 FBSDK 的自定义类,而 swift 不认为它是 uiButton,这就是为什么没有突出显示属性出现的原因.因此,我的目标是通过您的帮助人员找到它,这是找到一种方法,让 facebookLoginButton 在 swift 中被视为 uiButton.

actually the major problem is that facebookLogInButton is customized class for FBSDK and swift doesn't consider it as uiButton that's why no highlighting property appears. So the point I'm aiming to find it by your help guys is to find a way that let's facebookLoginButton to be considered as uiButton in swift.

这篇关于如何更改 FBSDKLoginButton iOS 8.3/Swift 1.2 的默认设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆