[iOS]创建单一像素的分割线
来源:互联网 发布:图书销售软件 编辑:程序博客网 时间:2024/05/21 06:19
直接上代码
Object-C :
/** * 生产一个 1像素的线 * * @param origin 线的起始位置(传入的点后面不要带小数) * @param length 线的长度 * @param isVertical 线的方向是否是垂直的 * @param color 线的颜色 * * @return 返回这根线 */- (UIView *)productSimplePixelLineViewWithOrigin:(CGPoint)origin length:(CGFloat)length isVertical:(BOOL)isVertical color:(UIColor *)color { CGFloat width = 1/[UIScreen mainScreen].scale; CGFloat offset = ((1/[UIScreen mainScreen].scale)/2); UIView *view; if (isVertical) { // 垂直的线 view = [[UIView alloc] initWithFrame:CGRectMake(ceil(origin.x) - offset, origin.y, width, length)]; } else { // 水平的线 view = [[UIView alloc] initWithFrame:CGRectMake(origin.x, ceil(origin.y) - offset, length, width)]; } view.backgroundColor = color; return view;}
Swift :
/**生产一个 1像素的线:param: origin 线的起始位置(传入的点后面不要带小数):param: length 线的长度:param: isVertical 线的方向是否是垂直的(默认是垂直的):param: color 线的颜色(默认是UITableViewCell 的分割线的颜色):returns: <span style="font-family: Arial, Helvetica, sans-serif;">返回这根线</span>*/func productSimplePixelLineView(origin: CGPoint, length: CGFloat, isVertical: Bool = true, color: UIColor = UIColor(red: 200/255.0, green: 199/255.0, blue: 204/255.0, alpha: 1.0)) -> UIView { let width = 1/UIScreen.mainScreen().scale let offset = ((1/UIScreen.mainScreen().scale)/2); let view = { () -> UIView in if isVertical { return UIView(frame: CGRect(x: ceil(origin.x) - offset, y: origin.y, width: width, height: length)) } else { return UIView(frame: CGRect(x: origin.x, y: ceil(origin.y) - offset, width: length, height: width)) } }() view.backgroundColor = color return view}
0 0
- [iOS]创建单一像素的分割线
- StoryBoard中一像素的分割线
- iOS 解决tableview分割线右缩进15像素问题
- iOS -- UITableViewCell的分割线
- 补全tableView分割线的左边的15像素
- ios TableViewCell的分割线
- iOS UITableViewCell的分割线缩进
- iOS 画分割线的问题
- iOS tableView的分割线短一节
- iOS TableView的cell分割线格式
- iOS 自定义UITableViewCell的分割线
- iOS分割线的操作方式
- iOS tableView cell的分割线设置
- iOS表视图分割线的总结
- ios 横分割线 纵分割线
- iOS -- navigationBar分割线
- TableViewCell分割线为一个像素点
- ios tableview 那些事(二十) ios7 分割线短 15 像素
- C# post数据时 出现如下错误: System.Net.WebException: 操作超时
- [Objective-C] Categories 小例子
- iOS UINavigationController跳转到指定页面
- 自定义标签
- java实习日记三
- [iOS]创建单一像素的分割线
- 视频截图一无编解码截图
- leetCode 3. Longest Substring Without Repeating Characters 解法与思路
- js返回星期方法
- linux升级相关
- SolrCloud Hello Word
- C# Deflate、GZip压缩与解压缩
- 黑马程序员----ios的核心架构的学习
- Android Studio 学习笔记-新手入门-(1)第一个案例