我尝试在Facebook SDK中创建自定义共享按钮,但我遇到了问题。在Facebook文档之后,在我的案例中分享Button看起来像这样:
let content = FBSDKShareLinkContent()
content.contentTitle = "\(postTitle)"
content.contentURL = NSURL(string:"\(www)")
let shareButton = FBSDKShareButton()
shareButton.shareContent = content
shareButton.center = selfview.center
self.view.addSubiview(shareButton)
它有效,但我有一个默认按钮,在我的布局中看起来不太好。我想有可能使用我自己的按钮facebookShareButton: UIButton
分享我的内容。我是否有可能在自己的按钮中调用此操作?如果是,我该怎么做?
答案 0 :(得分:3)
我有解决这个问题的方法:
我们需要创建一个UIButton插座,例如viewDidLoad()
,然后在 facebookOutlet.addTarget(self, action: #selector(ViewController.postFacebook(_:)), forControlEvents: .TouchUpInside)
中添加代码
viewDidAppear()
然后在let content = FBSDKShareLinkContent()
content.contentTitle = "\(postTitle)"
content.contentURL = NSURL(string:"\(www)")
let shareButton = FBSDKShareButton()
shareButton.shareContent = content
shareButton.center = self.view.center
self.view.addSubview(shareButton)
我们需要添加:
func postFacebook(sender: UIButton){
shareButton.sendActionsForControlEvents(.TouchUpInside)
}
然后在按钮的操作中,我们需要添加:
public static void main(String[] args) {
// ["a 100", "b 32", "t 54", "u 1"]
List<String> myList = new ArrayList<>();
myList.add("a 100");
myList.add("b 32");
myList.add("t 54");
myList.add("u 1");
System.out.println("List unsorted" + myList);
Collections.sort(myList, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
try {
int a1 = Integer.parseInt(o1.substring(2));
int a2 = Integer.parseInt(o2.substring(2));
return Integer.compare(a1,a2);
} catch (NumberFormatException ex) {
return 0;
}
}
});
System.out.println("List sorted" + myList);
}
它完美无缺,允许我们创建自定义的Facebook按钮。
答案 1 :(得分:0)
使用最新的FBSDKShareKit,您可以将以下内容添加到自定义按钮的操作处理程序中
let dialog = ShareDialog()
dialog.shareContent = content
dialog.show()