Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6156321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:35:21+00:00 2026-05-23T20:35:21+00:00

Why is my custom UIView not rendering within the UIView container of it’s parent?

  • 0

Why is my custom UIView not rendering within the UIView container of it’s parent? So what I have is:

  • MainViewController – has a UIView “customViewContainer” (which doesn’t take up the whole screen), and
  • CustomView – is a UIView with a XIB file – it is the UIView here that when it is rendered (with AspectFit) is rendering outside the bounds of the parent “customViewContainer“

The code used to setup the custom view is this extract from MainViewController:

<< cut – see Update2 below >>

So I can’t see why the CustomView view is being rendered in a way that is larger in area than the parent customViewContainer? What I want is for the customview to fit into the parent “customViewContainer” entirely per the AspectFit type approach.

thanks

EDIT 1 (added clarification) – If I “clip subviews” in the parent view then it does then clip things, but what I really need to render the custom view within the parent view area (not the whole area of the screen). So I need (a) the center of the custom view to be in the center of the parent view, and (b) custom view to AspectFit into the parent view properly. Any ideas?

EDIT 2 – Update

sorry – made a copy/paste mistake with code in the original question – can’t seem to edit it so I’ll put a correct version below – so to clarify:

MainViewController – has a UIView “containerView” (which doesn’t take up the whole screen), and CustomView – is a UIView with a XIB file – it is the UIView here that when it is rendered (with AspectFit) is rendering outside the bounds of the parent “containerView“

With the code below does this make sense now? The reason for this code is I have a custom UIView, BUT I have a XIB file associated with it, so this was the only way to get my MainController view to be able to use it. That is, have a container view in the MainController view, and then programmatically add the CustomView into the container view.

Re “So set the frame or center of the view that you’re adding to be what you want it to be” – are you saying I have to programmatically/manually set the dimension of the CustomView to be what I want (in relation to the parent containerView)?

What I was hoping was there was a way using the declaritive layout setting to some how be able to say “Load the Custom View from it’s XIB file, and the aspectFit this view into the self.containerView”, however I’m starting to wonder if this is possible?

UPDATED CODE BELOW (made mistake in original question when I copy/pasted it in and changed variables names etc)

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Load the custom Altimeter View into this UIControllerView's container UIView for it
    NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"Customview" owner:self options:nil];
    for (NSObject *obj in nibs) {
        if ( [obj isKindOfClass:[Customview class]]) {
            Customview *cv = (Customview*)obj;
            [self.containerView addSubview:cv];
            break;
        }
    }
    // UI Layout
    self.containerView.layer.borderWidth = 2;
    self.containerView.layer.borderColor = [[UIColor redColor] CGColor];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:35:23+00:00Added an answer on May 23, 2026 at 8:35 pm

    Check if the “Clip subviews” property of parent on the IB file is checked.

    Clip Subviews

    I think the equivalent code is self.view.clipsToBounds = YES.

    if this is NO, subviews that draws outside will be visible as if it’s drawn on the parent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom UIView which is composed of many images, their positions are
i have a custom UIView which is presented from a UIViewController . This view
I have a UIViewController Class which holds 2 custom UIView classes which are: ItemView
I have made a custom UIView which is shown when the user hits a
I have a custom UIView which is drawn using its -[drawRect:] method. The problem
I have created a custom UIView that has some set of UILabels in it.
I have created a custom UIView (without .xib) for a finger paint application. Paint
I have a custom UIView that contains an interactive drawing that is drawn in
I have a UIScrollView that contains a custom UIView. In my UIView I am
I have one ViewController, in this i have added one Custom UIView named as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.