iOS开发--画一条黑色的横线

在网上搜索了下大概有下面几种方法:

1.使用Quartz2D画出横线

 1 需要一个UIVIew把这两个Label装起来,你需要计算好他们的位置同时给黑线预留像素的位置。这样你在UIView里面- (void)drawRect:(CGRect)rect;用Quartz2D把这条黑线画出来。然后在相应的位置把Label加进去
 2 画线的方法如下:
 3 
 4 + (void)strokeLine:(const CGFloat*)strokeColor startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint (CGFloat)width {
 5     CGContextRef context = UIGraphicsGetCurrentContext();
 6     CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
 7     
 8     width = width >= 0 ? width : 1.0;
 9     
10     CGContextSaveGState(context);
11     CGContextSetStrokeColorSpace(context, space);
12     CGContextSetStrokeColor(context, strokeColor);
13     CGContextSetLineWidth(context, width);
14     
15     CGContextMoveToPoint(context, startPoint.x, startPoint.y);
16     CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
17     
18     CGContextRestoreGState(context);
19     
20     CGColorSpaceRelease(space);
21 } 

2.添加一个UIView,将背景颜色设成黑色,然后添加进去

1 UIview *ls=[[UIview alloc]initwithframe:CGRectMake(100,100,2,30)];//在100,100的位置添加一条2像素宽,30像素高的线。
2 ls.backgroundColor=[UIColor redColor];
3 [cell addsubview:is]; 

3.直接让美工切一个1px的图片,使用UIImageView添加进去

原文地址:https://www.cnblogs.com/feiling/p/4706094.html