在我的UIView中心设置圆圈

时间:2015-12-08 17:56:55

标签: ios objective-c

我有一个尺寸为141 X 161的UIView。然后我创建了一个圆圈。这是代码:

- (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是我的uiview

当我跑步时,它不在中心,

  1. 我需要我的圆圈在我的UIView(141 x 161)内部的完美中心。并且还需要设置外边界。

  2. 我的圈子是think.how将半径设置为1。

  3. 我的圈子填充应为#222222

  4. 边框:厚度= 1.9         颜色=白色          position = center

  5. 我是iOS的新手。

1 个答案:

答案 0 :(得分:1)

试试这个:

   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];