oc工具类

  1. + (NSString *)dealString:(NSString *)string  
  2. {  
  3.     NSString *returnString = @"";  
  4.     if (string) {  
  5.         if ([string isKindOfClass:[NSString class]]) {  
  6.             if (string.length > 0 && ![string isEqualToString:@"(null)"]) {  
  7.                 returnString = string;  
  8.             }  
  9.         } else {  
  10.             returnString = (NSString *)string;  
  11.         }  
  12.     }  
  13.     return returnString;  
  14. }  
  15.   
  16. + (int)convertToInt:(NSString *)str  
  17. {  
  18.     int strLength = 0;  
  19.     charchar *p = (charchar *)[str cStringUsingEncoding:NSUnicodeStringEncoding];  
  20.     int length = [str lengthOfBytesUsingEncoding:NSUnicodeStringEncoding];  
  21.       
  22.     for (int i = 0; i < length ; i ++) {  
  23.         if (*p) {  
  24.             strLength ++;  
  25.         }  
  26.         p ++;  
  27.     }  
  28.       
  29.     return strLength;  
  30. }  
  31.   
  32. + (BOOL)isEnglishAndNumberCharacter:(NSString *)str  
  33. {  
  34.     BOOL b = NO;  
  35.     if (str == nil) {  
  36.         return NO;  
  37.     } else {  
  38.         for (int i = 0; i < str.length; i ++) {  
  39.             unichar ch = [str characterAtIndex:i];  
  40.               
  41.             if (!((ch >= 48 && ch <=57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122))) {  
  42.                 b = YES;  
  43.                 break;  
  44.             }  
  45.         }  
  46.     }  
  47.     return b;  
  48. }  
  49.   
  50. + (BOOL)isEnglishAndNumberAndChiness:(NSString *)str  
  51. {  
  52.     BOOL b = NO;  
  53.     if (str == nil) {  
  54.         return b;  
  55.     } else {  
  56.         for (int i = 0; i < str.length; i ++) {  
  57.             unichar ch = [str characterAtIndex:i];  
  58.             if (!((ch >= 48 && ch <=57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || ch > 127)) {  
  59.                 b = YES;  
  60.                 break;  
  61.             }  
  62.         }  
  63.     }  
  64.     return b;  
  65. }  
  66.   
  67. + (BOOL)isNumberOfString:(NSString *)str  
  68. {  
  69.     BOOL b = NO;  
  70.     if (str == nil) {  
  71.         b = NO;  
  72.     } else {  
  73.         for (int i = 0; i < str.length; i ++) {  
  74.             unichar ch = [str characterAtIndex:i];  
  75.             if ( ch < 48 || ch > 57) {  
  76.                 b = YES;  
  77.                 break;  
  78.             }  
  79.         }  
  80.     }  
  81.     return b;  
  82. }  
  83.   
  84. + (void)changeCellBorder:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath  
  85. {  
  86.     if ([cell respondsToSelector:@selector(tintColor)]) {  
  87.         CGFloat cornerRadius = 5.f;  
  88.         cell.backgroundColor = UIColor.clearColor;  
  89.           
  90.         CAShapeLayer *layer = [[CAShapeLayer alloc] init];  
  91.         layer.strokeColor = [UIColor colorWithRed:209 / 255.0 green:212.0 / 255.0 blue:212.0 / 255.0 alpha:1.0].CGColor;  
  92.         CGMutablePathRef pathRef = CGPathCreateMutable();  
  93.           
  94.         CGRect bounds = CGRectInset(cell.bounds0.00);  
  95.         BOOL addLine = NO;  
  96.         if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {  
  97.             CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);  
  98.         } else if (indexPath.row == 0) {  
  99.             CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));  
  100.             CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);  
  101.             CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);  
  102.             CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));  
  103.             addLine = YES;  
  104.         } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {  
  105.             CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));  
  106.             CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);  
  107.             CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);  
  108.             CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));  
  109.         } else {  
  110.             CGPathAddRect(pathRef, nil, bounds);  
  111.             addLine = YES;  
  112.         }  
  113.         layer.path = pathRef;  
  114.         CFRelease(pathRef);  
  115.         layer.fillColor = [UIColor whiteColor].CGColor;  
  116.           
  117.         if (addLine == YES) {  
  118.             CALayer *lineLayer = [[CALayer alloc] init];  
  119.             CGFloat lineHeight = 1.f / [UIScreen mainScreen].scale;  
  120.             lineLayer.frame = CGRectMake(CGRectGetMinX(bounds), bounds.size.height-lineHeight, bounds.size.width, lineHeight);  
  121.             lineLayer.backgroundColor = [UIColor colorWithRed:226.0 / 255.0 green:226.0 / 255.0 blue:226.0 / 255.0 alpha:1.0].CGColor;  
  122.             [layer addSublayer:lineLayer];  
  123.         }  
  124.           
  125.         UIView *testView = [[UIView alloc] initWithFrame:bounds];  
  126.         [testView.layer insertSublayer:layer atIndex:0];  
  127.         testView.backgroundColor = [UIColor clearColor];  
  128.         cell.backgroundView = testView;  
  129.     }  
  130. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值