zoukankan      html  css  js  c++  java
  • 在iOS7中让表视图变成iOS6的圆角矩形与纯汉字文本的cell高度自适应

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([cell respondsToSelector:@selector(tintColor)]) {
            if (tableView == self.aTableView) {
                
                CGFloat cornerRadius = 5.f;
                cell.backgroundColor = UIColor.clearColor;
                CAShapeLayer *layer = [[CAShapeLayer alloc] init];
                CGMutablePathRef pathRef = CGPathCreateMutable();
                
                CGRect frame = cell.bounds;
                frame.origin.x = frame.origin.x+5;
                frame.size.width = frame.size.width-20;
                CGRect bounds = frame;
                
                BOOL addLine = NO;
                if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                    CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
                } else if (indexPath.row == 0) {
                    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
                    addLine = YES;
                } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
                    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
                    CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
                    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
                } else {
                    CGPathAddRect(pathRef, nil, bounds);
                    addLine = YES;
                }
                layer.path = pathRef;
                CFRelease(pathRef);
                layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.8f].CGColor;
                
                if (addLine == YES) {
                    CALayer *lineLayer = [[CALayer alloc] init];
                    CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
                    lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight);
                    lineLayer.backgroundColor = tableView.separatorColor.CGColor;
                    [layer addSublayer:lineLayer];
                }
                UIView *testView = [[UIView alloc] initWithFrame:bounds];
                [testView.layer insertSublayer:layer atIndex:0];
                testView.backgroundColor = UIColor.clearColor;
                cell.backgroundView = testView;
    
            }
        }
    }
    /**
     *  计算方式:
        step1:数一下一行能显示几个汉字
        step2:算一下一共几行
        step3:如果汉字不满一行按一行一算
        step4:用行数乘以行高
     */
    
        int lineCount = 20;
        CGFloat lbContentHeight = lbQ.text.length / lineCount;
        if (lbQ.text.length % lineCount) {
            lbContentHeight++;
        }
        lbContentHeight *= 20;
  • 相关阅读:
    Android开发常见问题及解决方法
    Jquery chosen动态设置值实例介绍 select Ajax动态加载数据 设置chosen和获取他们选中的值
    Unity3d 基于物理渲染Physically-Based Rendering之实现
    Unity3d 基于物理渲染Physically-Based Rendering之specular BRDF
    Unity3d HDR和Bloom效果(高动态范围图像和泛光)
    unity3d 制造自己的水体water effect(一)
    unity3d shader之Roberts,Sobel,Canny 三种边缘检测方法
    Unity3d shader之卡通着色Toon Shading
    NVIDIA CG语言 函数之所有数学类函数(Mathematical Functions)
    Unity3d 使用DX11的曲面细分
  • 原文地址:https://www.cnblogs.com/zylike/p/3741768.html
Copyright © 2011-2022 走看看