1

Is it possible to add dynamically (for example by extending view controller) custom view with specific size like 50px height on bottom every view controller?

I'm using iOS8, autolayout and storybaords, I don't want to modify every single view in storyboard to add my view on bottom.

I'm trying to add in this way:

let view = CustomView(frame:CGRectMake(0, 0, self.view.frame.width, 50));
self.view.addSubview(view)

but view is placed over current controllers view, I need to be able to place is under controllers view, something like advert banner or Tab bar.

3
  • 1
    If you must do this, why not just use a UIViewController subclass that puts this view on the bottom, and then all your ViewControllers can be subclasses of this custom ViewController rather than the usual UIViewController. Commented Sep 22, 2015 at 14:49
  • I'm just looking for the easiest way to add it to my view controllers, could you give me some example of your idea? Commented Sep 22, 2015 at 14:54
  • 2
    This is probably the easiest way. Is my suggestion unclear? Have you tried writing the subclass? Have a look at the layoutSubviews method as well as insertSubview(_ view: UIView, atIndex index: Int) Commented Sep 22, 2015 at 14:55

1 Answer 1

1

Assuming you want the same view for all view controllers, I think I would just change my root view controller.

My new root view controller would have a container view to host your old root view controller, and your 50px tall view at the bottom.

Since you're using storyboards this shouldn't be to hard - I think you can do it largely without writing any code. Drag out a new view controller. Add a container view and your bottom view. Set up your constraints. Drag a segue connector from the container view to your old root view controller and set they type as "embed". Set the entry point to the scoreboard to be the new controller.

Here's a picture.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.