我想为UIImageView添加白色边框。我尝试了以下方法,但它不起作用:
UIImage *image = [UIImage imageNamed:imagePath];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.width = rect.size.width + 1; // create white right border
[imageView setBackgroundColor:[UIColor whiteColor]];
imageView.frame = rect;
[myViewView addSubview:imageView];
答案 0 :(得分:14)
我现在就像
那样做了 CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor whiteColor].CGColor;
sublayer.frame = CGRectMake(imageView.bounds.size.width, 0, 1, imageView.frame.size.height);
[imageView.layer addSublayer:sublayer];
答案 1 :(得分:1)
您可以创建一个大于UIImage视图的UIView,并将图像视图的框架设置为0,0,宽度+ 1,高度,这将添加额外的边。