【问题标题】:How change the global tint color in Xamarin forms of the iOS application?如何更改 iOS 应用程序的 Xamarin 表单中的全局色调颜色?
【发布时间】:2016-03-05 14:29:01
【问题描述】:

如何在 Xamarin 表单项目 (C#) 中更改我的 iOS 应用程序的全局色调颜色?

【问题讨论】:

    标签: c# ios xamarin xamarin.forms


    【解决方案1】:

    全局iOS tint颜色可以通过UIApplication.KeyWindow设置,当它可用时,应用程序启动后最早:

    using Foundation;
    using UIKit;
    
    namespace MyApp.iOS
    {
        [Register("AppDelegate")]
        public class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        {
            public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
            {
                global::Xamarin.Forms.Forms.Init();
                LoadApplication(new App());
                var result = base.FinishedLaunching(uiApplication, launchOptions);
    
                uiApplication.KeyWindow.TintColor = UIColor.Blue;
    
                return result; 
            }
        }
    }
    

    【讨论】:

    • 这不会改变按钮或选择器的颜色。有没有一种自动的方式让那些人获得全局色彩?
    【解决方案2】:

    在 Xamarin.iOS 项目中的应用程序完成启动方法中添加以下代码。

    Boolean result = base.FinishedLaunching(app, options);
    UIApplication.SharedApplication.KeyWindow.TintColor = UIColor.Green;
    return result;
    

    【讨论】:

    • 例如,我应该在 中为绿色填写什么?我不知道语法... @Abhimanyu
    • 因为在一个非常简单的示例中无法解释地包含 DependencyService 而被否决。
    • UIApplication.SharedApplication.KeyWindow.TintColor = UIColor.Green;
    • 这对我有用,至少它改变了我在我正在测试这个 sn-p 的穗应用程序的 UITableView 中的复选标记的颜色。
    猜你喜欢
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-27
    • 2015-10-07
    • 1970-01-01
    相关资源
    最近更新 更多