我正在使用此代码在Xamarin IOS中共享:
public void Share(string title, string content)
{
if (UIApplication.SharedApplication.KeyWindow == null || UIApplication.SharedApplication.KeyWindow.RootViewController == null)
return;
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
return;
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var imageToShare = UIImage.FromBundle("icon_120.png");
var itemsToShare = new NSObject[] { new NSString(content), imageToShare };
var shareStatusController = new UIActivityViewController(itemsToShare, null)
{
Title = title
};
//shareStatusController.NavigationController.NavigationBar.TintColor = UIColor.Black;
//rootController.NavigationController.NavigationBar.TintColor = UIColor.Black;
//shareStatusController.NavigationBar.TintColor = UIColor.FromRGB(0, 122, 255);
rootController.PresentViewController(shareStatusController, true, null);
Mvx.Resolve<IAnalyticsService>().LogEvent("Share button clicked.");
}
当我选择邮件时,我被重定向到http://take.ms/3KE4F。但是取消和发送按钮的颜色是白色的(在NavigationBar中)。如何更改此按钮的文字颜色?
我找到了文章 Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7。但是不知道如何使用Xamarin来应用它。感谢您的帮助。
答案 0 :(得分:1)
试试这个:
public void Share(string title, string content)
{
if (UIApplication.SharedApplication.KeyWindow == null || UIApplication.SharedApplication.KeyWindow.RootViewController == null)
return;
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
return;
//Share Barbutton tint
UIBarButtonItem.AppearanceWhenContainedIn (new [] {typeof(UINavigationBar)}).TintColor = UIColor.Cyan;
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var imageToShare = UIImage.FromBundle("icon_120.png");
var itemsToShare = new NSObject[] { new NSString(content), imageToShare };
var shareStatusController = new UIActivityViewController(itemsToShare, null)
{
Title = title
};
shareStatusController.CompletionHandler += (NSString arg1, bool arg2) => {
// Set it back to old theme theme
UIBarButtonItem.AppearanceWhenContainedIn (new [] {typeof(UINavigationBar)}).TintColor = UIColor.White;
};
rootController.PresentViewController(shareStatusController, true, null);
Mvx.Resolve<IAnalyticsService>().LogEvent("Share button clicked.");
}
在呈现控制器之前,您基本上设置了按钮色调,然后在完成处理程序中将其设置回来。