简体   繁体   中英

How to set frame of UIView in AutoLayout?

First of all I have read this answer .

But somehow, we have requirement to change view programatically. And we have use Autolayout all over.

I have code something like this,

 self.containerView.frame = CGRectMake(x,y,30,30);

This doesn't work. Though I can hide/show border. But I cannot change frame.

Please suggest any hack if not exact solution.

hope this will help

when auto layout is ON you can't update the frame or bound of an ui element.

so you should set the auto layout OFF and then change the frame of your element or if you already put lot of constraints for managing your view and don't want to delete them , you should update your constraint in such a way that constraint update your view.

second, if some object add programmatically in your view then your previously define constraint does not work on it .so for it you have to add constraint programmatically.

You can use the Autolayout Constraints tool, to make this process easier.

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