删除UINavigationBar边框会导致黑色状态栏

时间:2015-06-22 10:37:54

标签: c# ios xamarin xamarin.ios uinavigationbar

我尝试删除UINavigationBar下方here所示的边框:

NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
NavigationController.NavigationBar.ShadowImage = new UIImage ();

在app委托中我还设置了背景颜色:

UINavigationBar.Appearance.BackgroundColor = UIColor.FromRGB (247, 247, 247);

现在UINavigationBar没有所需的边框,导航栏的颜色也发生了变化。但现在状态栏是完全黑色的,没有任何显示。我尝试在 Info.plist 中设置状态栏的样式,但这也没有帮助。

我做错了什么?我是否必须以某种方式设置状态栏的背景?

现在我尝试在单独的项目中执行此操作并设置导航栏的背景颜色。状态栏不是黑色,但状态栏的颜色消失了。只有导航栏有颜色,但状态栏保持白色。 Normally通过设置条形色调,状态栏和导航栏应该具有相同的颜色。 E.g。

[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];

设置条纹色调没有效果,所以我设置了导航栏的背景颜色。

如何删除导航栏的边框并将状态和导航栏设置为相同的颜色?

2 个答案:

答案 0 :(得分:1)

我不记得我在哪里得到这个,但我认为它是在obj-c中,这是我使用的。

protected void GetPayslipReport(string employeename)
{
    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Payslip.rdlc");
    ReportViewer1.LocalReport.DataSources.Clear();

    int Empid = 0;
    string sQuery;
    sQuery = "SELECT * FROM salary WHERE (EmployeeName ='" + employeename + "'AND month='" + UserMonthList.SelectedItem.ToString() + "'AND Year ='" + UserYearList.SelectedItem.ToString() + "')";

    MySqlDataAdapter ada = new MySqlDataAdapter(sQuery, GlobalCS.objMyCon);
    DataSet ds = new DataSet();
    ada.Fill(ds);      

    ReportDataSource reportDataSource = new ReportDataSource();
    reportDataSource.Name = "DataSet1_salary";
    reportDataSource.Value = ds.Tables[0];
    ReportViewer1.LocalReport.DataSources.Add(reportDataSource);

        /*To get EmpID */
         sQuery = "SELECT EmpID FROM employee WHERE (EmployeeName ='" + employeename + "')";            
         MySqlCommand command = new MySqlCommand(sQuery, GlobalCS.objMyCon);
         MySqlDataReader reader = command.ExecuteReader();
         while (reader.Read())
          {
              Empid =  reader.GetInt32("EmpID");                 
          }
         reader.Close();
        /***/

    sQuery = "SELECT * FROM employee WHERE EmpID =" + Empid;
    MySqlDataAdapter ada2 = new MySqlDataAdapter(sQuery, GlobalCS.objMyCon);
    DataSet ds2 = new DataSet();
    ada2.Fill(ds2);

    ReportDataSource reportDataSource2 = new ReportDataSource();
    reportDataSource2.Name = "DataSet1_employee";
    reportDataSource2.Value = ds2.Tables[0];
    ReportViewer1.LocalReport.DataSources.Add(reportDataSource2);           

}

答案 1 :(得分:0)

因为其他方法没有按预期工作,我现在创建一个图像并将其设置为导航栏的背景,如下所示:

UIImage backgroundImage = ImageHelper.ImageWithColor (UINavigationBar.Appearance.BarTintColor, new CGRect (0, 0, 1, 1));
NavigationController.NavigationBar.SetBackgroundImage (backgroundImage, UIBarMetrics.Default);
NavigationController.NavigationBar.ShadowImage = new UIImage ();

这里是ImageHelper类:

using System;
using System.Drawing;

using CoreGraphics;
using Foundation;
using UIKit;

public class ImageHelper
{
    public ImageHelper ()
    {
    }

    public static UIImage ImageWithColor(UIColor color, CGRect rect){
        CGRect rectangleForImage = new CGRect (0, 0, rect.Width, rect.Height);
        UIGraphics.BeginImageContext (rectangleForImage.Size);
        CGContext context = UIGraphics.GetCurrentContext ();

        context.SetFillColor (color.CGColor);
        context.FillRect (rectangleForImage);

        UIImage image = UIGraphics.GetImageFromCurrentImageContext ();
        UIGraphics.EndImageContext ();

        return image;
    }
}