Search code examples
iosswiftxcodeautolayoutxib

How to apply Xib width conditionally based on device width?


how to fix the width of Xib based on device width? .I have created custom navigation bar with xib view ? but i am facing problem with width of the xib ? `func loadNavigation() {

    self.navigationController?.navigationBar.isHidden = false
    self.navigationController?.navigationBar.isTranslucent = false
    self.navigationItem.hidesBackButton = true
    self.navigationController?.navigationBar.addSubview(customNavigation.view)
    customNavigation.leftBtn?.isHidden = false
    customNavigation.rightBtn?.isHidden = false
    customNavigation.titleLbl?.isHidden = false
    customNavigation.titleLbl?.text = NSLocalizedString("Teacher Profile", comment: "")
    customNavigation.leftBtn?.addTarget(self, action: #selector(PTeacherProfileViewController.BackAction(_:)), for: UIControlEvents.touchUpInside)
    customNavigation.rightBtn?.addTarget(self, action: #selector(PTeacherProfileViewController.DownAction(_:)), for: UIControlEvents.touchUpInside)
}`

this is the way i am using navigation bar


Solution

  • view.frame.size.width =  UIScreen.main.bounds.width