Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改WKWebView中UIToolbar的背景色_Ios_Xamarin.ios - Fatal编程技术网

Ios 更改WKWebView中UIToolbar的背景色

Ios 更改WKWebView中UIToolbar的背景色,ios,xamarin.ios,Ios,Xamarin.ios,我正在使用Xamarin编写我的应用程序,但我可以翻译任何swift/objective-C响应 我有一个WKWebView,用于使用LoadHtmlString()显示数据。我想更改用户聚焦输入字段时显示在键盘上方的UIToolbar的背景色。现在,按钮文本颜色和背景颜色都是白色,因此按钮不可见 我可以使用UIBarButtonItem.Appearance.TintColor=UIColor.White更改按钮文本颜色,但这也会更改我的UINavigationBar中按钮的文本颜色。我宁愿将

我正在使用Xamarin编写我的应用程序,但我可以翻译任何swift/objective-C响应

我有一个WKWebView,用于使用LoadHtmlString()显示数据。我想更改用户聚焦输入字段时显示在键盘上方的UIToolbar的背景色。现在,按钮文本颜色和背景颜色都是白色,因此按钮不可见

我可以使用
UIBarButtonItem.Appearance.TintColor=UIColor.White更改按钮文本颜色,但这也会更改我的UINavigationBar中按钮的文本颜色。我宁愿将文本保留为白色,并更改UIToolbar的背景色

我可以使用
UIToolbar.Appearance.BackgroundColor=UIColor.Red稍微修改背景色,但这只是给UIToolbar添加了一种微妙的颜色,实际上并没有使工具栏变暗到可以看到白色文本的程度

以下是设置外观默认值的完整代码:

UIColor lightColor = UIColor.White;
UIColor themeColor = UIColor.Red;

UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);

UINavigationBar.Appearance.BarStyle = UIBarStyle.Black;
UINavigationBar.Appearance.BarTintColor = themeColor;
UINavigationBar.Appearance.Translucent = false;
UINavigationBar.Appearance.TintColor = lightColor;
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
{
    TextColor = lightColor  
});

UIStringAttributes navBarAttributes = new UIStringAttributes();
navBarAttributes.ForegroundColor = lightColor;
UINavigationBar.Appearance.TitleTextAttributes = navBarAttributes;


UITabBar.Appearance.BarTintColor = themeColor;      
UITabBar.Appearance.TintColor = lightColor;

UIToolbar.Appearance.BarTintColor = themeColor;
UIToolbar.Appearance.TintColor = lightColor;

UIBarButtonItem.Appearance.TintColor = lightColor;
UIButton.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = lightColor;
UIToolbar.Appearance.BackgroundColor = themeColor;
有没有一种方法可以在不必重新调整整个应用程序的情况下更改WKWebView的工具栏背景色

如果无法更改工具栏的背景色,则可以更改在WKWebView中显示的按钮文本颜色。我尝试添加以下代码,但似乎没有任何效果

//Using green to see if the code is working.
UIBarButtonItem.AppearanceWhenContainedIn(typeof(WKWebView)).TintColor = UIColor.Green;
UIBarButtonItem.AppearanceWhenContainedIn(typeof(MyViewController)).TintColor = UIColor.Green;

您可以尝试使用自定义
UIToolBar
通过图像更改其背景颜色:

 public class MyToolBar: UIToolbar
{
    public override void Draw(CGRect rect)
    {
        base.Draw(rect);
        CGContext c = UIGraphics.GetCurrentContext();
        UIImage image = new UIImage("background.png");
        //here set image to be background color
        c.DrawImage(rect, image.CGImage);
    }
}
而工具栏将只用于您使用过的地方,不能影响应用程序中的其他工具栏

MyToolBar myToolBar = new MyToolBar();
myToolBar.Frame = new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, 50);
UIBarButtonItem doneItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, doneClickMethod);
List<UIBarButtonItem> list = new List<UIBarButtonItem>();
list.Add(doneItem);
myToolBar.Items = list.ToArray();
MySearchBar.InputAccessoryView = myToolBar;
MyToolBar MyToolBar=newmytoolbar();
myToolBar.Frame=newcoregraphics.CGRect(0,0,UIScreen.MainScreen.Bounds.Size.Width,50);
UIBAButtonim doneItem=新的UIBAButtonim(“完成”,UIBAButtonimStyle.Done,doneClickMethod);
列表=新列表();
列表。添加(doneItem);
myToolBar.Items=list.ToArray();
MySearchBar.InputAccessoryView=myToolBar;

如何将自定义UIToolbar与WKWebView一起使用?@Dave如果在键盘上方添加工具栏,您可以参考此内容。可能我没有正确解释此问题。我没有创建任何UIToolbar。当用户选择网页中的可编辑字段(如标签)时,键盘上方的工具栏将自动显示。该栏包含“完成”按钮和箭头按钮,可前进到表单中的下一个字段。我想更改工具栏的背景色。@Dave Okey,你是说网页旁边的键盘?你能给我一个截图吗,我会检查一下。我已经用不同的方式编写了我的应用程序来解决这个问题,所以我不能轻易地提供截图。这个Stackoverflow用户也有类似的问题。他还求助于改变他的应用程序,因为你找不到解决问题的方法。