0

I want to draw a UIImageView in oval shape. i try to draw but i cloud not find answer. i show most of round or circle shape.
enter link description here
i try this but this is not work

#import <QuartzCore/QuartzCore.h>`
 CALayer *imageLayer = YourImageview.layer;
            [imageLayer setCornerRadius:5];
            [imageLayer setBorderWidth:1];
            [imageLayer setMasksToBounds:YES];

enter image description here

Community
  • 1
  • 1
Ilesh P
  • 3,940
  • 1
  • 24
  • 49

3 Answers3

8

If you want to draw an imageview in an oval shape, follow below steps:

  1. Create a UIBezierPath using bezierPathWithOvalInRect

    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:YOUR_RECT];
    
  2. Create a mask layer by using CAShapeLayer

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    
  3. Now set the bezier path as mask layer's path

    maskLayer.path = path.CGPath;
    
  4. Then we are going mask our view with our own mask layer.

    YourImageview.layer.mask = maskLayer;
    

That's all. Try it.

manujmv
  • 6,450
  • 1
  • 22
  • 35
1

Yes, you can done it by draw BezierPath but even we can't get exact round-rect image... so i'll give you other trick... you use 2 imageview one for main-imageview in which you pass your image.. second(overhead imageviw) for round or circle shape image with orange color border which is transparent in middle/center.

when you use overheadimageview over main imageview then you can find exact round or circle shape image

Rohit
  • 577
  • 1
  • 3
  • 13
0

You need to have a corner Radius half of what your image size is, to draw the cricular.
But to draw oval shape you need smaller radius.

CGFloat imgSize                      = 55;
UIImageView *imgViewProfile          = [[UIImageView alloc] init];
imgViewProfile.frame                 = CGRectMake(5, 5, imgSize, imgSize);
imgViewProfile.layer.cornerRadius    = imgSize / 2;
imgViewProfile.clipsToBounds         = YES;
imgViewProfile.contentMode           = UIViewContentModeScaleAspectFill;
[view addSubview:imgViewProfile];
Bishal Ghimire
  • 2,580
  • 22
  • 37