0
0

More than 1 year has passed since last update.

UIViewControllerのviewにxibを使用する

Posted at

概要

xibfileから、UIViewControllerのviewのoutletを紐付ける。

手順

1.xibfileのfile's ownerをViewControllerに指定する。これで、ViewControllerのviewのoutletがxibfile側から見えるようになる。
2.ViewControllerのviewのoutletに、xibfileのrootviewを紐付ける。
3.storyboardに紐づいているViewControllerの場合、storyboard側の実装が優先されるので、storyboard側ではViewControllerのviewを削除しておく。
Frameworks/dp/1492074616スクリーンショット 2021-04-24 18.36.38.png

感想

こういうやり方もあるのかーと言った感じ。

個人的には、XibviewのoutletがViewController内に洗われるのが嫌なので、XibviewをViewControllerのVIewとして使う場合は、xibfileのfileOwnerにUIView指定して、そのUIViewをViewControllerのloadView()内でviewに指定する方が好きかな、と思う。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0