【发布时间】:2015-04-15 08:46:09
【问题描述】:
我有一个 CALayer,它是一个圆形图像,我正在尝试为此添加一个外部边框。 (阴影在这里对我不起作用)。我已尝试调整 CALAyer 的大小并添加边框,但定位似乎不正确,我不希望形状移动,只需添加边框。
这是我的代码
CGFloat borderWidth = 10.0f;
CGFloat xPos = cont.layer.frame.origin.x;
CGFloat yPos = cont.layer.frame.origin.y;
CGFloat contWidth = cont.layer.frame.size.width;
CGFloat contHeight = cont.layer.frame.size.width;
cont.layer.frame = CGRectMake(xPos, yPos, contWidth + borderWidth, contHeight + borderWidth);
cont.layer.cornerRadius = contWidth / 2;
cont.layer.borderColor = [[UIColor darkGrayColor] CGColor];
cont.layer.borderWidth = borderWidth;
提前致谢
【问题讨论】:
-
不是 100% 确定你在这里做了什么,但是你似乎只在这一行中考虑了边框宽度一次.. cont.layer.frame = CGRectMake(xPos, yPos, contWidth + borderWidth, contHeight + 边框宽度);也许你的意思是 contWidth + borderWidth * 2 或类似的东西,这取决于你想走的路
-
我已经给出了答案检查它。只需在您的代码下方添加该行。
-
我的原始图层移动了位置,我希望它保持在同一个地方并且边框出现在外面?
-
你的答案在哪里?
-
那么为什么要弄乱框架呢?为什么不直接设置图层的边框宽度、颜色和半径?
标签: ios objective-c xcode border calayer