我正在试图在UIView
的顶部和底部边缘上绘制线条。但是这条线不会一直画到视图控制器的右边。在UIView上绘制顶部和底部线条
以下是代码我用来绘制线条:
- (void)addBorders
{
CALayer *upperBorder = [CALayer layer];
CALayer *bottomBorder = [CALayer layer];
upperBorder.backgroundColor = [[UIColor colorWithRed:225/255.0 green:220/255.0 blue:214/255.0 alpha:1.0f] CGColor];
upperBorder.frame = CGRectMake(0, 0, CGRectGetWidth(self.recentTuneinView.frame), 0.5f);
bottomBorder.backgroundColor = [[UIColor colorWithRed:154/255.0 green:154/255.0 blue:154/255.0 alpha:1.0f] CGColor];
bottomBorder.frame = CGRectMake(0, 58.0f, CGRectGetWidth(self.recentTuneinView.frame), 0.5f);
[self.recentTuneinView.layer addSublayer:upperBorder];
[self.recentTuneinView.layer addSublayer:bottomBorder];
}
这里是一个图像显示的问题:
什么我的代码所缺少?
谢谢。
看到这个链接可能会帮助你http://stackoverflow.com/questions/17355280/how-to-add-a-border-just-on-the-top-side-of-a-uiview –
它是您的方法被调用时不清楚;绘图应该发生在例如'-drawInRect:'方法。 – holex
它没有使它正确,然后增加cgrectframe中的值 –