一些零碎的知识点。希望能帮到大家,我也是刚入行的小白~
判断密码长度 这里是(6-20位)
#pragma mark -密码长度
- (BOOL) validatePassword:(NSString *)passWord
{
NSString *passWordRegex = @"^[a-zA-Z0-9]{6,20}+$";
NSPredicate *passWordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passWordRegex];
return [passWordPredicate evaluateWithObject:passWord];
}
打电话
#pragma mark - 打电话
- (void)finshTelPhone
{
//打电话
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString:@"tel://10086"]];
}
倒叙排布
#pragma mark - 倒叙排布
- (void)daoxu
{
NSArray *array = @[@"1",@"2",@"3",@"5",@"6"];
[array enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"%@",obj);
}];
}
部分字符串替换 *
NSString *originTel = @"13722223333";
NSString *tel = [originTel stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
NSLog(@"tel:%@",tel);
颜色转图片
/**
* 颜色转图片
*/
-(UIImage*) createImageWithColor:(UIColor*) color
{
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
判断字符串是否为空
- (BOOL)isKindOfNullString:(NSString *)string{ if (string==nil||[string isEqualToString:@""]||[string isEqual:[NSNull null]]||[string isKindOfClass:[NSNull class]]||[string isEqualToString:@""])
{
return NO;
}
else{
return YES;
}
}
判断类型是否为空
/**
* 判断类型是否为空
*
* @param any 任意类型
*
* @return yes执行 No retrurn
*/
- (BOOL)isNullForid:(id)any
{
if ([any isKindOfClass:[NSNull class]]==YES||[any isEqual:[NSNull null]]==YES||any==nil)
{
return NO;
}
else{
return YES;
}
}
隐藏TableView的滚动条
/**
* 隐藏表的滚动条
*/
- (void)hideTableView:(UITableView *)tableview
{
tableview.showsVerticalScrollIndicator = NO;
}
↑返回顶部
/**
* 返回顶部
*
* @param tableview
*/
- (void)backToTopButtonWithTableView:(UITableView *)tableview
{
UIButton * btn_GoTop = [UIButton buttonWithType:0];
[btn_GoTop setBackgroundImage:[UIImage imageNamed:@"回到顶部"] forState:UIControlStateNormal];
btn_GoTop.frame = CGRectMake( SCREEN_WIDTH-50, SCREEN_HEIGHT-180, 40, 40);
self.tableview = tableview;
[btn_GoTop addTarget:self action:@selector(GotoTopClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn_GoTop];
[self.view bringSubviewToFront:btn_GoTop];
}
按钮 图片上文字下
/**
* 按钮 图片上文字下
*
* @param btn
*/
-(void)initButton:(UIButton*)btn{
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height+20 ,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
[btn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,0.0, -btn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
}
判断手机号
#pragma mark - 判断手机号
// 正则判断手机号码地址格式
- (BOOL)isMobileNumber:(NSString *)mobileNum {
// 电信号段:133/153/180/181/189/177
// 联通号段:130/131/132/155/156/185/186/145/176
// 移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178
// 虚拟运营商:170
NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
return [regextestmobile evaluateWithObject:mobileNum];
}