两个UIViews外面最小的矩形 - ObjectiveC

时间:2023-02-09 17:45:53

I have two UIViews and I need to draw a rectangle (or) get the frame of the smallest rectangle outside both the UIViews. How can I get this?

我有两个UIViews,我需要绘制一个矩形(或)获取UIViews外的最小矩形的框架。我怎么能得到这个?

2 个解决方案

#1


6  

You can use:

您可以使用:

CGRect smallestRectangle = CGRectUnion(view1.frame, view2.frame);

According to the docs, this function

根据文档,这个功能

Returns the smallest rectangle that contains the two source rectangles.

返回包含两个源矩形的最小矩形。

#2


0  

here are some steps that should work to find the rectangle you want

这里有一些步骤可以找到你想要的矩形

  • find the left most origin.x... = new origin.x
  • 找到最左边的origin.x ... = new origin.x

  • find the top most origin.y... = new origin.y
  • 找到最顶层的origin.y ... = new origin.y

  • find the largest (origin.x + size.width)... = new size.width
  • 找到最大的(origin.x + size.width)... = new size.width

  • find the largest (origin.y + size.height)... = new size.height
  • 找到最大的(origin.y + size.height)... = new size.height

#1


6  

You can use:

您可以使用:

CGRect smallestRectangle = CGRectUnion(view1.frame, view2.frame);

According to the docs, this function

根据文档,这个功能

Returns the smallest rectangle that contains the two source rectangles.

返回包含两个源矩形的最小矩形。

#2


0  

here are some steps that should work to find the rectangle you want

这里有一些步骤可以找到你想要的矩形

  • find the left most origin.x... = new origin.x
  • 找到最左边的origin.x ... = new origin.x

  • find the top most origin.y... = new origin.y
  • 找到最顶层的origin.y ... = new origin.y

  • find the largest (origin.x + size.width)... = new size.width
  • 找到最大的(origin.x + size.width)... = new size.width

  • find the largest (origin.y + size.height)... = new size.height
  • 找到最大的(origin.y + size.height)... = new size.height