如何用红色绘制UIImageView框架



我想把UIImageView的帧画成红色,这样我可以在旋转和缩放时看到它。设置图层边框宽度和颜色不是我需要的,因为如果我旋转它,它也会旋转图层(而UIImageView帧不会旋转)。这可能吗?有人知道怎么做吗?

将其放置在一个背景色为红色的较大的UIView上。

UIView *redBackgroundView = [[UIView alloc] initWithFrame: … /* a bigger frame than imageView*/)];
[redBackgroundView: addSubview: imageview];
[self.view addSubview: redBackgroundView];

你可以使用UIImageView对象的backgroundColor属性将UIImageView的背景色设置为红色

Add frame #import "QuartzCore/QuartzCore.h"

UIImageView *imgReport = [[UIImageView alloc] initWithFrame:CGRectMake(50, 20,250,150)] ;
    imgReport.backgroundColor = [UIColor yellowColor];
    imgReport.layer.cornerRadius = 7.0; // change cornerRadius as per you requriment
    imgReport.layer.masksToBounds = YES;
    imgReport.layer.borderColor = [UIColor redColor].CGColor;
    imgReport.layer.borderWidth = 5.0;
 [self.view addSubview:imgReport];

最新更新