Xamarin.iOS 导航栏各个位置按钮设置

开发中基本上每个界面都会有导航栏,来控制你每个界面从哪来到哪去。

通常的情况都是导航栏左侧一个返回按钮,中间文字展示这个界面是干嘛的。

偶尔也会出现右侧一个图标或者文字,来增加一些功能。本篇介绍一下几个简单位置按钮设置。

1.设置中间文字。

一般都放在ViewController的构造里面,下同。

UILabel titleUILabel = new UILabel(new CGRect(0, 0, 100, 35));
			titleUILabel.Text = "中间文字";
			NavigationItem.TitleView = titleUILabel;
			titleUILabel.TextAlignment = UITextAlignment.Center;
			titleUILabel.TextColor = UIColor.White;
2.设置右侧按钮(图片)。

// 右侧成长记录按钮
			var rightImg = UIImage.FromBundle("图片资源路径");
			UIBarButtonItem rightBtn = new UIBarButtonItem(rightImg, UIBarButtonItemStyle.Plain
				, (sender, e) =>
				{
					// 点击事件
				});
			NavigationItem.SetRightBarButtonItem(rightBtn, true);



3.左侧返回按钮(文字代替),右侧按钮(文字)

// 标题右侧保存按钮
			UIBarButtonItem rightItem = new UIBarButtonItem("保存", UIBarButtonItemStyle.Plain, (sender, e) =>
			{
				// 右侧文字点击
			});
			NavigationItem.SetRightBarButtonItem(rightItem, true);

			// 取消按钮
			UIBarButtonItem leftItem = new UIBarButtonItem("取消", UIBarButtonItemStyle.Plain
				, (sender, e) =>
				{
					// 左侧文字点击
				});
			NavigationItem.SetLeftBarButtonItem(leftItem, true);







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值