Botao Like customized

0

Does anyone know if it is possible to customize like button of facebook SDK ? I need to use my image as the background 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)
    
asked by anonymous 05.06.2015 / 23:45

1 answer

0

I do not know if this is the best way, but it worked cool here:

Youwillneedtochangethefacebookframeworkclassdirectly,ashereIinstalledtheSDKviacocoapodsIcanaccessthefolderscontainingtheclasses:

Then just open the class FBSDKButton that is inside Pods > FBSDKCoreKit > arc search 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];
...
    
06.06.2015 / 10:37