のツールバーを使用したくありませんUINavigationController
。UIToolbar
代わりにセパレートを使用したい。
要件:
- 常に画面に表示
- の下部の位置にとどまる必要があります
UIView
(のツールバーのようにUINavigationController
) - 幅を調整する必要があります(例:回転後)
- IB/ストーリーボード ソリューションなし
- さらに: のコンテンツを非表示にしないでください。
UITableView
これには自動レイアウトを使用したいと思います。私のコードは C# ですが、Objective-C のソリューションはいつでも提供できます。
これは では機能しviewDidLoad
ますが、では機能しUIViewController
ません:viewDidLoad
UITableViewController
UIView toolbar = new UIView ();
toolbar.BackgroundColor = UIColor.Red;
toolbar.TranslatesAutoresizingMaskIntoConstraints = false;
View.AddSubview (toolbar);
NSLayoutConstraint toolbarBottom = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, BottomLayoutGuide, NSLayoutAttribute.Top, 1, 0);
NSLayoutConstraint toolbarLeft = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0);
NSLayoutConstraint toolbarRight = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0);
NSLayoutConstraint toolbarHeight = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 40);
this.View.AddConstraints (new NSLayoutConstraint[] { toolbarBottom, toolbarLeft, toolbarRight, toolbarHeight });
テスト上の理由から、 のUIView
代わりに を使用しましたUIToolbar
。結果は非常に似ています。UIViewController
赤いビューが表示されます。では、UITableViewController
まったく表示されません。
自動レイアウトを使用せずに別のテストを行いました。
RectangleF toolbarFrame = new RectangleF (0, this.View.Bounds.Height - 44, this.View.Bounds.Width, 44);
UIView toolbar = new UIView (toolbarFrame);
toolbar.BackgroundColor = UIColor.Red;
View.AddSubview (toolbar);
ここではUIView
が表示されていますが、テーブル ビューの固定位置にあり、区切り線が透けて見えます。私が望むものではありませんが、UIToolbar
上に配置することは可能だと思われUITableView
ます...