简体   繁体   中英

Increase height of UIView above UITableView

I added a UIView above a UITableView via the storyboard. I was wondering if there is a good way to increase the height of the UIView programmatically and push down the table cells. The UITableView is a static table.

I'm using this code:

CGRect newFrame = myUIView.frame;
newFrame.size.height = 300;
myUIView.frame = newFrame;

With this code, the UIView height is increasing, but it is overlapping the table cells below it. Is there any way to "push" the tableview lower?

thanks!

Since you are using storyboard, the easiest and cleanest way is to just change the size of the UITableView and move it down to make room for the UIView . You then can move/change the UIView to whatever size you want.

Non-storyboard solution. Change the frame of the UITableView also.

self.tableView.frame = CGRectMake(x,y,height,width);

If you are using autolayout this is pretty simple.
Pin the height of the UIView. This will create an NSLayoutConstraint for the height. Then create a property for this and update in your code as required.

@property (weak, nonatomic) IBOutlet UIView *uiview1;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *uiViewHeight;

Update the height constant of the constraint and then update the UIView constraints. The UITableView will change to accommodate the modified UIView.

self.uiViewHeight.constant = 150.0f;
[self.uiview1 setNeedsUpdateConstraints]; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM