iPhone-两个UIView最小的矩形

有两个UIView,需要绘制一个矩形,或获取两个UIView框架最小的矩形。

应该怎么实现?

问题描述不明确。
如果在UIView中绘制矩形,在-(void)drawRect 中来画。

-(void)drawRect {
    CGRect rect=self.bounds;
    CGContextRef context=UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context,[UIColor redColor].CGColor);
    CGContextSetFillRect (context, rect);
}

使用:

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

文档说明中,实现功能是:

Returns the smallest rectangle that contains the two source rectangles。

很符合你的要求啦