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 width:(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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值