iOS--喜闻乐见④

  • Plain类型TableView的HeaderView和FooterView不停靠上下边缘
    大家都知道Plain的tableView头尾视图会附着在上下边缘,现在我不想让它附着了(去掉黏性),方法如下①:
    自定义HeaderView.h:
iOS--喜闻乐见④_第1张图片
自定义HeaderView.png

HeaderView.m

iOS--喜闻乐见④_第2张图片
HeaderView.png

自定义FooterView.h

iOS--喜闻乐见④_第3张图片
定义FooterView.png

FooterView.m

iOS--喜闻乐见④_第4张图片
FooterView.png

使用:

headerView使用.png
footerView使用.png

方法②
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 5;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)
{
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}
else if (scrollView.contentOffset.y>=sectionHeaderHeight)
{
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}

  • 正则判断
    //邮箱
    + (BOOL) validateEmail:(NSString *)email {
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
    }
    //手机号码验证
    + (BOOL) validateMobile:(NSString *)mobile {
    //手机号以13, 15,18开头,八个 \d 数字字符
    NSString *phoneRegex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
    }
    //用户名
    + (BOOL) validateUserName:(NSString *)name {
    NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";
    NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
    BOOL B = [userNamePredicate evaluateWithObject:name];
    return B;
    }
    //密码
    + (BOOL) validatePassword:(NSString *)passWord {
    NSString *passWordRegex = @"^[a-zA-Z0-9]{6,12}+$";
    NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
    return [passWordPredicate evaluateWithObject:passWord];
    }
    //身份证号
    + (BOOL) validateIdentityCard: (NSString *)identityCard {
    BOOL flag;
    if (identityCard.length <= 0) {
    flag = NO;
    return flag;
    }
    NSString *regex2 = @"^(\d{14}|\d{17})(\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
    }
    //数字
    + (BOOL) validateCount: (NSString *)count {
    NSString countRegex = @"^[0-9]$";
    NSPredicate *countTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", countRegex];
    return [countTest evaluateWithObject:count];
    }
    //网址
    + (BOOL) validateURL:(NSString )URL
    NSString URLRegex1 = @"^\w+((\-\w+)|(\.\w+))@[A-Za-z0-9]+((\.|\-)[A-Za-z0-9]+)
    .[A-Za-z0-9]+$";
    NSPredicate *URLTest1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", URLRegex1];
    NSString URLRegex2 = @"http+:[^\s]";
    NSPredicate *URLTest2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", URLRegex2];
    if ([URLTest1 evaluateWithObject:URL] == YES || [URLTest2 evaluateWithObject:URL] == YES) {
    return YES;
    }else {
    return NO;
    }
    }

  • 十六进制数字转颜色
    + (UIColor *)colorWithHexString:(NSString *)hexString {
    unsigned int red,green,blue;
    NSRange range;
    range.length = 2;
    range.location = 0;
    [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&red];
    range.location = 2;
    [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&green];
    range.location = 4;
    [[NSScanner scannerWithString:[hexString substringWithRange:range]]scanHexInt:&blue];
    return [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green / 255.0f) blue:(float)(blue / 255.0f)alpha:1.0f];
    }

  • 星星评分(传参型,支持NIB和代码)
    StarView.h

    iOS--喜闻乐见④_第5张图片
    StarView.png

    StarView.m
    - (instancetype) initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
    self.backgroundColor = [UIColor clearColor];//主背景颜色为透明
    [self _creatView];
    }
    return self;
    }
    - (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor clearColor];//主背景颜色为透明
    [self _creatView];
    }
    - (void)_creatView {
    //创建灰黄星星
    UIImage *yellowImg = [UIImage imageNamed:@"StarsForeground"];//灰星星图片
    UIImage *grayImg = [UIImage imageNamed:@"StarsBackground"];//黄星星图片
    _grayView = [[UIView alloc]initWithFrame:CGRectMake(0.f, 0.f, grayImg.size.width * 5.f, grayImg.size.height)];//灰星星图片frame
    _grayView.backgroundColor = [UIColor colorWithPatternImage:grayImg];//灰星星图片背景颜色
    [self addSubview:_grayView];//加载灰星星图片
    _yellowView= [[UIView alloc]initWithFrame:CGRectMake(0.f, 0.f, yellowImg.size.width * 5.f, yellowImg.size.height)];//黄星星图片frame
    _yellowView.backgroundColor = [UIColor colorWithPatternImage:yellowImg];//黄星星图片背景颜色
    [self addSubview:_yellowView];//加载黄星星图片
    // 计算缩放倍数
    CGFloat scale = self.frame.size.height / yellowImg.size.height;
    //放大倍数
    CGAffineTransform t = CGAffineTransformMakeScale(scale, scale);//高宽同比例缩放
    _grayView.transform = t;
    _yellowView.transform = t;
    //星星视图修改transform后,坐标会被改变,重新恢复坐标
    _yellowView.origin = CGPointZero;
    _grayView.origin = CGPointZero;
    }
    - (void)setRating:(CGFloat)rating {
    if (_rating != rating) {
    _rating = rating;
    CGFloat s = [self backFloatWithRatingFloat:_rating];
    CGFloat yellowWidth = s * self.frame.size.width;
    _yellowView.width = yellowWidth;//将比例后宽度设置为黄星星宽度
    }
    }
    //大于等于N.5的按N+1算,小于N.f按大于N按N.5算,等于N按N算(0 < N <5)
    - (CGFloat) backFloatWithRatingFloat:(CGFloat)ratingFloat {
    if (ratingFloat == floorf(ratingFloat)) {
    return floorf(ratingFloat) / 5.f;
    }else if (ratingFloat > floorf(ratingFloat) && ratingFloat <= (floorf(ratingFloat) + 0.5)) {
    return (floorf(ratingFloat) + 0.5f) / 5.f;
    }else {
    return (floorf(ratingFloat) + 1.f) / 5.f;
    }
    }
    - (void)layoutSubviews {
    [super layoutSubviews];
    //创建灰黄星星
    UIImage *yellowImg = [UIImage imageNamed:@"StarsForeground"];//灰星星图片
    UIImage *grayImg = [UIImage imageNamed:@"StarsBackground"];//黄星星图片
    _grayView.backgroundColor = [UIColor colorWithPatternImage:grayImg];//灰星星图片背景颜色
    _yellowView.backgroundColor = [UIColor colorWithPatternImage:yellowImg];//黄星星图片背景颜色
    }

PS:评分为五星满分,可自行修改成自己的需求(backFloatWithRatingFloat:)

  • 查看ipa支持版本(32位,64位)
    取出ipa的执行文件,在终端输入otool -vh ipa执行文件路径

  • 显示/隐藏文件
    //显示
    defaults write com.apple.finder AppleShowAllFiles -bool true
    killall Finder
    //隐藏
    defaults write com.apple.finder AppleShowAllFiles -bool false
    killall Finder

  • 查看工程量
    find . -name ".m" -or -name ".h" -or -name ".xib" -or -name ".c" |xargs wc -l

  • 获取iOS设备的型号
    +(NSString*)deviceString {
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    if ([deviceString isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
    if ([deviceString isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
    if ([deviceString isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
    if ([deviceString isEqualToString:@"iPhone3,1"]) return @"iPhone 4 GSM";
    if ([deviceString isEqualToString:@"iPhone3,2"]) return @"iPhone 4 WCDMA";
    if ([deviceString isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
    if ([deviceString isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
    if ([deviceString isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
    if ([deviceString isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
    if ([deviceString isEqualToString:@"iPad1,1"]) return @"iPad";
    if ([deviceString isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
    if ([deviceString isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
    if ([deviceString isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
    if ([deviceString isEqualToString:@"i386"]) return @"Simulator";
    if ([deviceString isEqualToString:@"x86_64"]) return @"Simulator";
    NSLog(@"NOTE: Unknown device type: %@", deviceString); return deviceString;
    }
    //获取系统版本
    NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by u
    NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string
    NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS"
    NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1"
    NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices
    NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices
    float version = [[[UIDevice currentDevice] systemVersion] floatValue];

补全

iOS--喜闻乐见④_第6张图片
获取系统版本.png

你可能感兴趣的:(iOS--喜闻乐见④)