两个 CGRect 的总和
Sum of Two CGRect
如何得到两个 CGRect 的总和
CGRect requiredFirst = [firstName boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];
CGRect requiredLast = [lastName boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];
CGRect 高度 = ???
求身高总和:
CGFloat height = requiredFirst.size.height + requiredLast.size.height;
下面是一个方法示例:
- (CGRect)combineFrames:(CGRect)frame1, f2:(CGRect)frame2{
CGFloat x = frame1.origin.x + frame2.origin.x;
CGFloat y = frame1.origin.y + frame2.origin.y;
CGFloat width = frame1.size.width + frame2.size.width;
CGFloat height = frame1.size.height + frame2.size.height;
CGRect combinedFrame = CGRectMake(x, y, width, height);
return combinedFrame;
}
此方法只是将框架的所有四个方面(x、y、宽度、高度)单独相加,然后重建它并 returns 它。
像这样使用它:
CGRect combinedFrame = [self combineFrames:requiredFirst, f2:requiredLast];
CGFloat height = combinedFrame.size.height;
如何得到两个 CGRect 的总和
CGRect requiredFirst = [firstName boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];
CGRect requiredLast = [lastName boundingRectWithSize:constrainedSize options:NSStringDrawingUsesLineFragmentOrigin context:nil];
CGRect 高度 = ???
求身高总和:
CGFloat height = requiredFirst.size.height + requiredLast.size.height;
下面是一个方法示例:
- (CGRect)combineFrames:(CGRect)frame1, f2:(CGRect)frame2{
CGFloat x = frame1.origin.x + frame2.origin.x;
CGFloat y = frame1.origin.y + frame2.origin.y;
CGFloat width = frame1.size.width + frame2.size.width;
CGFloat height = frame1.size.height + frame2.size.height;
CGRect combinedFrame = CGRectMake(x, y, width, height);
return combinedFrame;
}
此方法只是将框架的所有四个方面(x、y、宽度、高度)单独相加,然后重建它并 returns 它。 像这样使用它:
CGRect combinedFrame = [self combineFrames:requiredFirst, f2:requiredLast];
CGFloat height = combinedFrame.size.height;