How to add only the right border in UIImageView

I want to add a white border to the UIImageView. I tried the following, but that did not work:

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]; 
+6
source share
2 answers

Now i made it like

  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]; 
+13
source

You can create a UIView, which is larger than the UIImage view, and set the viewing frame of the image to 0.0, width + 1, height, and this will add an extra side.

+1
source

Source: https://habr.com/ru/post/917468/


All Articles