简体   繁体   中英

Set circle in centre of my UIView

I have one UIView with size 141 X 161. Then I created a circle .Here is that code:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CAShapeLayer *circleLayer = [CAShapeLayer layer];
    [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 86, 79)] CGPath]];
    [[self.photoView layer] addSublayer:circleLayer];

    [circleLayer setStrokeColor:[[UIColor blackColor] CGColor]];
    [circleLayer setFillColor:[[UIColor clearColor] CGColor]];
}

photoview is my uiview

When I run it's not in centre,

  1. I need my circle in perfect centre of inside my UIView ( 141 x 161). And also need to set outside border.

  2. And my circle is think.how to set radius at 1.

  3. And my circle fill should be #222222

  4. Border: thickness = 1.9 color = white position = centre

I am new to iOS.

Try this :

   CAShapeLayer *circleLayer = [CAShapeLayer layer];
    [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(27, 41, 86, 79)] CGPath]];
    [[self.photoView layer] addSublayer:circleLayer];
  [circleLayer setStrokeColor:[[UIColor whiteColor] CGColor]];
    [circleLayer setFillColor:[[UIColor clearColor] CGColor]];
    circleLayer.lineWidth = 0.5;



    circleLayer.shadowColor = [UIColor whiteColor].CGColor;

    circleLayer.shadowOpacity = 0.4;
    circleLayer.borderColor = [UIColor whiteColor] .CGColor;
    circleLayer.borderWidth = 2;
    circleLayer.fillColor =[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.25].CGColor;

    circleLayer.borderColor = [[UIColor whiteColor] CGColor];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM