Xamarin IOS:更改共享 window 中的色调颜色
Xamarin IOS: Change tint color in share window
我正在使用此代码在 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 应用它。
感谢您的帮助。
试试这个:
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.");
}
您基本上是在呈现控制器之前设置按钮色调,然后在完成处理程序中将其重新设置。
我正在使用此代码在 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 应用它。
感谢您的帮助。
试试这个:
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.");
}
您基本上是在呈现控制器之前设置按钮色调,然后在完成处理程序中将其重新设置。