国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

在iOS7中讓表視圖變成iOS6的圓角矩形與純漢字文本的cell高度自適應(yīng)

2019-11-14 20:28:47
字體:
供稿:網(wǎng)友
- (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;        }    }}

 

/** *  計(jì)算方式:    step1:數(shù)一下一行能顯示幾個漢字    step2:算一下一共幾行    step3:如果漢字不滿一行按一行一算    step4:用行數(shù)乘以行高 */    int lineCount = 20;    CGFloat lbContentHeight = lbQ.text.length / lineCount;    if (lbQ.text.length % lineCount) {        lbContentHeight++;    }    lbContentHeight *= 20;

 

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿鲁科尔沁旗| 监利县| 龙山县| 平谷区| 繁峙县| 八宿县| 洮南市| 靖安县| 蓝山县| 新乡县| 铜梁县| 荔浦县| 台中市| 郎溪县| 十堰市| 浮山县| 禹州市| 乌拉特前旗| 察雅县| 松原市| 龙岩市| 若羌县| 富阳市| 铜梁县| 宁明县| 仲巴县| 赤峰市| 肥西县| 平江县| 广元市| 方城县| 曲阜市| 定结县| 玉门市| 铜川市| 泌阳县| 大竹县| 芜湖市| 上杭县| 无极县| 南靖县|