開發中基本上每個界面都會有導航欄,來控制你每個界面從哪來到哪去。
通常的情況都是導航欄左側一個返回按鈕,中間文字展示這個界面是干嘛的。
偶爾也會出現右側一個圖標或者文字,來增加一些功能。本篇介紹一下幾個簡單位置按鈕設置。
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);
| 
 
 | 
新聞熱點
疑難解答