我在使用UIButtons
, type 时遇到了一个奇怪的问题custom
。我将其中的 4 个按钮放在 a 上UIScrollview
,使用 .将每个按钮旋转一个随机角度CGAffineTransform
。现在似乎按钮本身会根据旋转角度改变大小。
UIGraphicsBeginImageContext(tempCtxSize);
[cookbookImage drawInRect:CGRectMake(imgOffsetX, imgOffsetY+frmOffsetY, cookbookImage.size.width, cookbookImage.size.height)];
[cookbookFrame drawInRect:CGRectMake(0.0f, frmOffsetY, cookbookFrame.size.width, cookbookFrame.size.height)];
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
…
UIButton *cookbookViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cookbookViewButton setFrame:CGRectMake(0.0f, 0.0f, combinedImage.size.width, combinedImage.size.height)];
[cookbookViewButton setBackgroundColor:[UIColor clearColor]];
[cookbookViewButton setBackgroundImage:combinedImage forState:UIControlStateNormal];
CGAffineTransform rotation = [cookbookViewButton transform];
rotation = CGAffineTransformRotate(rotation, angle); // some random angle
[cookbookViewButton setTransform:rotation];