[英]How to add a subview with constraints to make the subview with the same frame as its superview?
[英]How to make a superview resize automatically same size and coordinate with its subview?
我有一個包含UIImageView
的UIVIew
。 我想使UIView
與UIImageView
具有相同的大小和坐標。 我該怎么做?
以編程方式自動調整大小。
首先,取消選中自動布局,這是屏幕截圖。
添加自動調整大小的代碼
>
myView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
myView.autoresizingMask=UIViewAutoresizingFlexibleHeight;
嘗試這個
//myview : UIView
//imageview:UIImageview
CGRect frame1=myview.frame;
CGRect frame2=imageView.frame;
CGRect frame3=CGRectMake(frame1.origin.x+frame2.origin.x, frame1.origin.y+frame2.origin.y, frame2.size.width, frame2.size.height);
[myview setFrame:frame3];
[imageView setFrame:myView.bounds];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.