Custom Like Boot

Asked

Viewed 63 times

0

Does anyone know if it is possible to customize the like button of facebook SDK? I need to use my image as the bottom of the button or make it a button.

    var likeControl:FBSDKLikeControl = FBSDKLikeControl()
    likeControl.objectID = fbPage
    likeControl.likeControlStyle = FBSDKLikeControlStyle.BoxCount
    likeControl.backgroundColor = UIColor(patternImage: UIImage(named: "fblike")!)
    likeControl.frame = CGRectMake(16,20, 290, 40)
    self.viewBotoes.addSubview(likeControl)

1 answer

0

I don’t know if this is the best way, but it worked out nice here:

resultado


You will need to change the facebook framework class directly, as here I installed the SDK via cocoapods i can access the folders containing the classes:

inserir a descrição da imagem aqui


So you just need to open up the class FBSDKButton that’s inside Pods > FBSDKCoreKit > arc look for the method that starts with _configureWithIcon:(FBSDKIcon *)icon and add the following code in the same place as below:

...
  BOOL forceSizeToFit = CGRectIsEmpty(self.bounds);

  CGFloat scale = [UIScreen mainScreen].scale;
  UIImage *backgroundImage;

  // Crie um novo UIImage com a sua imagem
  UIImage *custom = [UIImage imageNamed:@"backCustomLike"];

  backgroundImage = [self _backgroundImageWithColor:backgroundColor cornerRadius:3.0 scale:scale];

  // Coloque a sua nova imagem aqui
  [self setBackgroundImage:custom forState:UIControlStateNormal];

  backgroundImage = [self _backgroundImageWithColor:highlightedColor cornerRadius:3.0 scale:scale];
  [self setBackgroundImage:backgroundImage forState:UIControlStateHighlighted];

  backgroundImage = [self _backgroundImageWithColor:[self defaultDisabledColor] cornerRadius:3.0 scale:scale];
  [self setBackgroundImage:backgroundImage forState:UIControlStateDisabled];
...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.