2016-07-07 3 views
2

SDK에서 Facebook 로그인 버튼을 가지고있어 텍스트를 변경하고 싶습니다. 나는이 코드를 시도했다 :Swift에서 프로그래밍 방식으로 Facebook 버튼의 텍스트를 변경하는 방법은 무엇입니까?

facebookButton.setTitle("my text here", forState: .Normal) 

그러나 작동하지 않는다. 그것을 할 수있는 방법이 있습니까?

이 좋아하는 페이스 북의 로그인 버튼 코드는 모습입니다 : 당신은 FBLoginViews에 이동하여 버튼의 텍스트를 변경 시도 할 수 있습니다

//MARK: Facebook Login 

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 
    if error == nil { 

     facebookAPILogin(FBSDKAccessToken.currentAccessToken().tokenString, completionHandler: { error in 

     if error == nil { 

      self.performSegueWithIdentifier("loginToHomeSegue", sender: self) 

     } else { 



      self.showAlertWithTitle("Sorry".localized(), message: "There was a problem connecting with Facebook".localized()) 

      print(error) 

     } 
     } 
    ) 

    } else { 

     showAlertWithTitle("Sorry".localized(), message: "There was a problem connecting with Facebook".localized()) 

     print(error.localizedDescription) 

    } 
    } 


    //Facebook Logout 

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) { 
    print("User logged out") 

    } 

답변

4

난 그냥 오답 많이 방문한 후, 발견, 그것은이다 :

let buttonText = NSAttributedString(string: "your text here") 
facebookButton.setAttributedTitle(buttonText, for: .normal) 
+0

현재 Objective-C를 사용하고 있지만 컨셉은 켜져 있습니다. 나는 FBSDKLoginButton과 FBSDKButton에 대한 소스를보고있다. FBSDKLoginButton은 몇 가지 속성을 추가하고 FBSDKButton을 확장합니다. FBSDKButton은 새 속성이나 함수를 추가하지 않고 UIButton을 확장합니다. 따라서 UBSutton의 모든 개념은 FBSDKLoginButton에 존재합니다. 이것은 분명해야하지만, 때로는 가장 단순한 개념을 실현해야합니다. 감사! – Armand

+0

은 tvos에서 작동하지 않습니다 – reggie

-1

을 일부 VC와에서 작업하는 것을 가정하여 loginButton 속성은 FBSDKLoginButton입니다.

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 

    [self.loginButton setAttributedTitle:[[NSAttributedString alloc] initWithString:@"test"] 
           forState:UIControlStateNormal]; 

} 
+0

@Andreza Cristina da Silva의 답변과 다른 점은 무엇입니까? –

관련 문제