本文介绍了Xamarin iOS 共享按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何像在原生开发中一样在 Xamarin.iOS 中实现社交分享?
How to implement in Xamarin.iOS social sharing like in native development?
推荐答案
可以这样做:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
var button = new UIButton (UIButtonType.RoundedRect) {
Frame = UIScreen.MainScreen.Bounds,
BackgroundColor = UIColor.Red
};
button.TouchUpInside += (sender, e) => {
var item = NSObject.FromObject ("HI");
var activityItems = new NSObject[] { item };
UIActivity[] applicationActivities = null;
var activityController = new UIActivityViewController (activityItems, applicationActivities);
PresentViewController (activityController, true, null);
};
Add (button);
}
您共享的项目必须来自 NSObjects.
The items you share have to be derived from NSObjects.
并且您可以通过在 UIActivityViewController
通过上面的代码,我在模拟器中得到了这个:
With the code above I get this in the simulator:
这篇关于Xamarin iOS 共享按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!