iOS 画分割线的问题
来源:互联网 发布:江恩九方图软件 编辑:程序博客网 时间:2024/06/10 08:31
很多控件中希望加一条线, 常见横的竖的, 比如在一个页面的header里, cell中, 像tableview那样那样的分割线.
所以我总结了几种方式供大家参考:
1. 利用CGContext去画, 举个例子:
- UIImageView *imageView=[[UIImageView alloc] initWithFrame:self.view.frame];
- [self.view addSubview:imageView];
- self.view.backgroundColor=[UIColor blueColor];
- UIGraphicsBeginImageContext(imageView.frame.size);
- [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];
- CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
- CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0); //线宽
- CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
- CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); //颜色
- CGContextBeginPath(UIGraphicsGetCurrentContext());
- CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 100, 100); //起点坐标
- CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 200, 100); //终点坐标
- CGContextStrokePath(UIGraphicsGetCurrentContext());
- imageView.image=UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
2. 利用UIView, 我看到过有同学直接设置UIView宽或高为1来做线条:
- UIView *line_view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320.f, 1.f)];
- [line_view setBackgroundColor:[UIColor redColor]];
- [self.view addSubview:line_view];
这样就是一条红色的横线lol
3. 利用UIImageView:
- UIImage *separatorImage = [UIImage imageWithRenderColor:[UIColor redColor] renderSize:CGSizeMake(320.f, 1)];
- UIImageView *topSeparatorView = [[UIImageView alloc] initWithImage:separatorImage];
- topSeparatorView.center = CGPointMake(320.f*0.5, 0.5);
- [self addSubview:topSeparatorView];
上述就是总结的三种横线画法, 当然还有其他很多方式, 有想法的可以留言.
0 0
- iOS 画分割线的问题
- iOS -- UITableViewCell的分割线
- iOS开发中tableView的分割线的处理问题
- ios 9 tableview分割线不全的问题
- iOS UITableViewCell 分割线不到左部顶端的问题!
- iOS 画一条分割线
- cell的分割线问题
- iOS TableView 分割线(separator)显示问题
- iOS TableView分割线左边少一截问题
- ios TableViewCell的分割线
- iOS UITableViewCell的分割线缩进
- [iOS]创建单一像素的分割线
- iOS tableView的分割线短一节
- iOS TableView的cell分割线格式
- iOS 自定义UITableViewCell的分割线
- iOS分割线的操作方式
- iOS tableView cell的分割线设置
- iOS表视图分割线的总结
- 欢迎使用CSDN-markdown编辑器
- spotlight软件,监控mysql的软件
- Java对象的序列化和反序列化
- Android数据绑定库Data Binding Library介绍
- 快速幂取余
- iOS 画分割线的问题
- NSString属性什么时候用copy,什么时候用strong?
- CSS中的绝对定位与相对定位
- GDI+屏幕截图
- [LeedCode OJ]#213 House Robber II
- 判断一棵树是否是另一棵树的子树
- 提示错误OCIEnvCreate 失败,返回代码为 -1
- Java 接口和抽象类
- c++程序设计书本P360.5