我想为UI
ImageView添加白色边框.我尝试了以下,但它不起作用:
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];
解决方法
我现在就这样做了
CALayer *sublayer = [CALayer layer]; sublayer.backgroundColor = [UIColor whiteColor].CGColor; sublayer.frame = CGRectMake(imageView.bounds.size.width,1,imageView.frame.size.height); [imageView.layer addSublayer:sublayer];