我认为有一个标签。现在,我想在标签上方绘制一条线,这意味着您可以看到标签在该线下方。

到目前为止,我可以使用quartz2D画一条线,但始终在标签下。有什么办法可以解决我的问题?

最佳答案

您可以这样创建CAShapeLayer

CAShapeLayer *lineLayer = [CAShapeLayer layer];
lineLayer.frame = self.label.bounds;
lineLayer.strokeColor = [UIColor redColor].CGColor;

CGRect rect = CGRectMake(0, CGRectGetMidY(lineLayer.bounds), lineLayer.bounds.size.width, 2);
lineLayer.path = [UIBezierPath bezierPathWithRect:rect].CGPath;


然后像这样将其添加到UILabel中:

[self.label.layer addSublayer:lineLayer];

关于ios - iOS在标签上方画一条线,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19322589/

10-10 22:24