开发者社区 问答 正文

关于iPhone-两个UIView最小的矩形

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

应该怎么实现?

展开
收起
爵霸 2016-03-19 09:57:05 2232 分享 版权
2 条回答
写回答
取消 提交回答
  • 用CGRectUnion()和CGRectIntersection()获取两个矩形的交并。使用时,传入两个UIView的frame即可

    2019-07-17 19:07:23
    赞同 展开评论
  • 问题描述不明确。
    如果在UIView中绘制矩形,在-(void)drawRect 中来画。

    -(void)drawRect {
        CGRect rect=self.bounds;
        CGContextRef context=UIGraphicsGetCurrentContext();
    
        CGContextSetFillColorWithColor(context,[UIColor redColor].CGColor);
        CGContextSetFillRect (context, rect);
    }
    2019-07-17 19:07:23
    赞同 展开评论
问答地址: