如何解决iOS 中是否有类似 android:actionBarSize 的属性?
我正在 Xamarin 中开发,我不知道如何更改导航栏的高度。 对于 android 更容易,因为你有一个明确的属性“ActionBarSize”
我尝试了很多东西。使用 HeightRequest 属性创建一个 comun NavigationPage 不起作用
非常感谢
解决方法
在 iOS 中,我们可以使用自定义渲染器设置自定义 TitlView。
using Foundation;
using UIKit;
using Xamarin.Forms.Platform.iOS;
using Xamarin.Forms;
using xxx.iOS;
using CoreGraphics;
using xxx;
using ObjCRuntime;
[assembly: ExportRenderer(typeof(ContentPage),typeof(MyPageRenderer))]
namespace xxx.iOS
{
public class MyPageRenderer: PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var page = Element as ContentPage;
NavigationController.NavigationBar.Hidden = true;
double height = IsiphoneX();
UIView backView = new UIView()
{
BackgroundColor = UIColor.White,Frame = new CGRect(0,20,UIScreen.MainScreen.Bounds.Width,height),};
UIButton backBtn = new UIButton() {
Frame = new CGRect(20,height-44,40,44),Font = UIFont.SystemFontOfSize(18),} ;
backBtn.SetTitle("Back",UIControlState.Normal);
backBtn.SetTitleColor(UIColor.Blue,UIControlState.Normal);
backBtn.AddTarget(this,new Selector("GoBack"),UIControlEvent.TouchUpInside);
UILabel titleLabel = new UILabel() {
Frame=new CGRect(UIScreen.MainScreen.Bounds.Width/2-75,150,Font = UIFont.SystemFontOfSize(20),Text = page.Title,TextColor = UIColor.Black,Lines = 0,};
UILabel line = new UILabel() {
Frame = new CGRect(0,height,0.5),BackgroundColor = UIColor.Black,};
backView.AddSubview(backBtn);
backView.AddSubview(titleLabel);
backView.AddSubview(line);
View.AddSubview(backView);
}
double IsiphoneX()
{
double height = 44; //set height as you want here !!!
if (UIDevice.CurrentDevice.CheckSystemVersion(11,0))
{
if (UIApplication.SharedApplication.Delegate.GetWindow().SafeAreaInsets.Bottom > 0.0)
{
height = 64; //set height as you want here !!!
}
}
return height;
}
[Export("GoBack")]
void GoBack()
{
NavigationController.PopViewController(true);
}
public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);
NavigationController.NavigationBar.Hidden = false;
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。