工具1

+ (NSString *)dealString:(NSString *)string
{
    NSString *returnString = @"";
    if (string) {
        if ([string isKindOfClass:[NSString class]]) {
            if (string.length > 0 && ![string isEqualToString:@"(null)"]) {
                returnString = string;
            }
        } else {
            returnString = (NSString *)string;
        }
    }
    return returnString;
}

+ (int)convertToInt:(NSString *)str
{
    int strLength = 0;
    char *p = (char *)[str cStringUsingEncoding:NSUnicodeStringEncoding];
    int length = [str lengthOfBytesUsingEncoding:NSUnicodeStringEncoding];
    
    for (int i = 0; i < length ; i ++) {
        if (*p) {
            strLength ++;
        }
        p ++;
    }
    
    return strLength;
}

+ (BOOL)isEnglishAndNumberCharacter:(NSString *)str
{
    BOOL b = NO;
    if (str == nil) {
        return NO;
    } else {
        for (int i = 0; i < str.length; i ++) {
            unichar ch = [str characterAtIndex:i];
            
            if (!((ch >= 48 && ch <=57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122))) {
                b = YES;
                break;
            }
        }
    }
    return b;
}

+ (BOOL)isEnglishAndNumberAndChiness:(NSString *)str
{
    BOOL b = NO;
    if (str == nil) {
        return b;
    } else {
        for (int i = 0; i < str.length; i ++) {
            unichar ch = [str characterAtIndex:i];
            if (!((ch >= 48 && ch <=57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || ch > 127)) {
                b = YES;
                break;
            }
        }
    }
    return b;
}

+ (BOOL)isNumberOfString:(NSString *)str
{
    BOOL b = NO;
    if (str == nil) {
        b = NO;
    } else {
        for (int i = 0; i < str.length; i ++) {
            unichar ch = [str characterAtIndex:i];
            if ( ch < 48 || ch > 57) {
                b = YES;
                break;
            }
        }
    }
    return b;
}

+ (void)changeCellBorder:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(tintColor)]) {
        CGFloat cornerRadius = 5.f;
        cell.backgroundColor = UIColor.clearColor;
        
        CAShapeLayer *layer = [[CAShapeLayer alloc] init];
        layer.strokeColor = [UIColor colorWithRed:209 / 255.0 green:212.0 / 255.0 blue:212.0 / 255.0 alpha:1.0].CGColor;
        CGMutablePathRef pathRef = CGPathCreateMutable();
        
        CGRect bounds = CGRectInset(cell.bounds, 0.0, 0);
        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 whiteColor].CGColor;
        
        if (addLine == YES) {
            CALayer *lineLayer = [[CALayer alloc] init];
            CGFloat lineHeight = 1.f / [UIScreen mainScreen].scale;
            lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);
            lineLayer.backgroundColor = [UIColor colorWithRed:226.0 / 255.0 green:226.0 / 255.0 blue:226.0 / 255.0 alpha:1.0].CGColor;
            [layer addSublayer:lineLayer];
        }
        
        UIView *testView = [[UIView alloc] initWithFrame:bounds];
        [testView.layer insertSublayer:layer atIndex:0];
        testView.backgroundColor = [UIColor clearColor];
        cell.backgroundView = testView;
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章