Evgeniy Kleban Evgeniy Kleban - 2 months ago 16x
Objective-C Question

Increase height of UIView without Auto Layout

For specific reason i need to create UIView by "old" style, without Auto Layout and constraints. In my view is table view, which is calculate it size by auto layout mechanism, and other view. Unfortunately it appears, that view itself cant comes out with height i need. This is how i create UI:

// 1 view

FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, height)];
calendar.dataSource = self;
calendar.delegate = self;

calendar.scopeGesture.enabled = YES;

[view addSubview:calendar];

// 2 view - table view

_myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
self.myTableView.tableFooterView = [UIView new];
self.myTableView.backgroundColor = self.view.backgroundColor;
[self.myTableView setShowsHorizontalScrollIndicator:NO];
[self.myTableView setShowsVerticalScrollIndicator:NO];
// self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.myTableView.estimatedRowHeight = 85.0;
self.myTableView.rowHeight = UITableViewAutomaticDimension;
_myTableView.bounces = NO;
self.myTableView.dataSource = self;
self.myTableView.delegate = self;
self.myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.myTableView.cellLayoutMarginsFollowReadableWidth = NO;

[self.view addSubview:_myTableView];

I suppose problem might be here:

_myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];

Because, space that i missing is about 200 points (y position that i move table view from top to bottom in initializer).

Is there any way to fit screen height to my views?


If this view is inside another view, it should be resized in layoutSubviews.

- (void)layoutSubviews
    [super layoutSubviews];

    // your code here...

If it is inside of a viewController's view do the resizing in viewDidLayoutSubviews.

- (void)viewDidLayoutSubviews
    [super layoutSubviews];

    // your code here...