【发布时间】:2015-10-16 14:11:34
【问题描述】:
我正在尝试在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];
}
这是显示问题的图像:
我在代码中遗漏了什么?
谢谢。
【问题讨论】:
-
看到这个链接可能对你有帮助stackoverflow.com/questions/17355280/…
-
不清楚你的方法何时被调用;绘图应该发生在内部,例如
–drawInRect:方法。 -
它没有正确然后增加 cgrectframe 中的值
-
方法在
viewDidLoad中调用 -
@Anbu.Karthik :我从您提供的链接中获得了上述代码。谢谢
标签: ios objective-c uiview