Change the table view to an iOS6 rounded rectangle and cell height Self-adaptive for Chinese text in iOS7

Source: Internet
Author: User

- (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;        }    }}

 

/*** Calculation method: Step 1: display a few Chinese Characters in one row. Step 2: calculate the total number of rows. Step 3: if the number of Chinese characters is less than one row, calculate one row. Step 4: multiply the number of rows by the Row Height */int lineCount = 20; CGFloat lbContentHeight = lbQ. text. length/lineCount; if (lbQ. text. length % lineCount) {lbContentHeight ++;} lbContentHeight * = 20;

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.