How to customize text on the Facebook Login Button?

PavelKovalevPavelKovalev ✭✭USMember, University ✭✭

Hey guys,

I'm trying to find a way to customize "Log in with Facebook" text.
I have a button on a view and its name is "btnFacebook" and its class is "FBSDKLoginButton". Everything works as a charm, I just need to change this text.

I'm pretty desperate... I'll appreciate any help.
Thank you.

Answers

  • haydenmellinshaydenmellins ✭✭ USMember ✭✭

    Hi Pavel,

    I can help you for this work, please share your contact(email or Skype) details so that we can discuss.

    Thanks

  • pauloroachpauloroach USMember

    Hi @haydenmellins, could you please share your knowledge in the forum to others like me who are trying the same thing can solve this problem?

    thank you very much

  • kunalthakkarkunalthakkar ✭✭ INMember ✭✭

    Can you guys please post some solution so it can help to us.

    Thanks

  • br.pantabr.panta BRMember

    I figured it out.
    The easiest way to do that is using NSAttributedString. It's even possible to change font size, color and other stuff.
    Following is the code:

    var facebookLoginButtonText = new NSAttributedString("[Your text here]",
    new UIStringAttributes()
        {
            ForegroundColor = UIColor.White
        });
    FacebookLoginButton.SetAttributedTitle(facebookLoginButtonText, UIControlState.Normal);
    
  • joilson.cisnejoilson.cisne ✭✭ BRMember ✭✭
    edited March 2017

    @br.panta Do you know how to do it on Android?

    @br.panta said:
    I figured it out.
    The easiest way to do that is using NSAttributedString. It's even possible to change font size, color and other stuff.
    Following is the code:

    var facebookLoginButtonText = new NSAttributedString("[Your text here]",
    new UIStringAttributes()
    {
    ForegroundColor = UIColor.White
    });
    FacebookLoginButton.SetAttributedTitle(facebookLoginButtonText, UIControlState.Normal);

  • Roman.TelishevskyiRoman.Telishevskyi USMember
    edited March 2017

    @joilson.cisne said:
    @br.panta Do you know how to do it on Android?

    You can just do your custom button and than bind facebook callback to it on android! For example:

    private Button facebookButton;
    
    protected override void OnCreate (Bundle bundle)
    {
            base.OnCreate (bundle);
    
            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.login_view);
    
            FacebookSdk.SdkInitialize(this.ApplicationContext);
            callbackManager = CallbackManagerFactory.Create();
            LoginManager.Instance.RegisterCallback(callbackManager, this);
    
            facebookButton = FindViewById<Button>(Resource.Id.facebook_button);
            facebookButton.Click += OnFacebookButtonClick;
    }
    
    protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)
    {
            base.OnActivityResult(requestCode, resultCode, data);
            callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
    }
    
    private async void OnFacebookButtonClick(object sender, System.EventArgs e)
    {
            var accessToken = AccessToken.CurrentAccessToken?.Token;
    
            if (accessToken == null)
            {
                LoginManager.Instance.LogInWithReadPermissions(this, new[] { "public_profile", "email" });
            }
            else
            {
                //Do whatever you want when already logged in
            }
    }
    
  • Roman.TelishevskyiRoman.Telishevskyi USMember

    @joilson.cisne said:
    @br.panta Do you know how to do it on Android?

    You can just bind login action to any button on android! For example:

    public class LoginView : Activity, IFacebookCallback
    {
        private ICallbackManager callbackManager;
    
            private Button facebookButton;
    
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
    
            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.login_view);
    
            FacebookSdk.SdkInitialize(this.ApplicationContext);
            callbackManager = CallbackManagerFactory.Create();
            LoginManager.Instance.RegisterCallback(callbackManager, this);
    
            facebookButton = FindViewById<Button>(Resource.Id.facebook_button);
            facebookButton.Click += OnFacebookButtonClick;
        }
        protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
        }
    
        public void OnCancel()
        {
        }
    
        public void OnError(FacebookException p0)
        {
            Toast.MakeText(this, p0.ToString(), ToastLength.Long).Show();
        }
    
        public void OnSuccess(Java.Lang.Object p0)
        {
            //Save token and do what you need
        }
    
        private void OnFacebookButtonClick(object sender, System.EventArgs e)
        {
            var accessToken = AccessToken.CurrentAccessToken?.Token;
    
            if (accessToken == null)
            {
                LoginManager.Instance.LogInWithReadPermissions(this, new[] { "public_profile", "email" });
            }
            else
            {
                //Do smth when already logged in
            }
        }
    
    }
    
  • Roman.TelishevskyiRoman.Telishevskyi USMember

    @joilson.cisne said:
    @br.panta Do you know how to do it on Android?

    You can just bind login action to any button on android! For example:

    public class LoginView : Activity, IFacebookCallback
    {
        private ICallbackManager callbackManager;
    
            private Button facebookButton;
    
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
    
            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.login_view);
    
            FacebookSdk.SdkInitialize(this.ApplicationContext);
            callbackManager = CallbackManagerFactory.Create();
            LoginManager.Instance.RegisterCallback(callbackManager, this);
    
            facebookButton = FindViewById<Button>(Resource.Id.facebook_button);
            facebookButton.Click += OnFacebookButtonClick;
        }
        protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
        }
    
        public void OnCancel()
        {
        }
    
        public void OnError(FacebookException p0)
        {
            Toast.MakeText(this, p0.ToString(), ToastLength.Long).Show();
        }
    
        public void OnSuccess(Java.Lang.Object p0)
        {
            //Save token and do what you need
        }
    
        private void OnFacebookButtonClick(object sender, System.EventArgs e)
        {
            var accessToken = AccessToken.CurrentAccessToken?.Token;
    
            if (accessToken == null)
            {
                LoginManager.Instance.LogInWithReadPermissions(this, new[] { "public_profile", "email" });
            }
            else
            {
                //Do smth when already logged in
            }
        }
    
    }
    
Sign In or Register to comment.