【1】键盘遮挡的一种解决方法:
主要实现逻辑: 将需要显示的控件放置在一个单独的UIView中,然后整个view上移处理
代码实现:
+(void)animationView:(UIScrollView *)anmaView activeRect:(CGRect)filedRect
{
// CGRect filedRect=filed.frame;
CGPoint point=anmaView.contentOffset;
// 计算出距离屏幕上方的相对坐标高度
float realDis=filedRect.origin.y-point.y;
// 计算到目标点的距离的绝对值
int distance1=0;
if (iPhone5) {
distance1=120;
}else{
distance1=90;
}
float distance=fabsf(realDis-distance1);
if (realDis>distance1) {
point.y+=distance;
}else{
point.y-=distance;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
anmaView.contentOffset=point;
[UIView commitAnimations];
}
【2】移动号码验证(网络转载,已验证)
- (BOOL)isMobileNumber:(NSString*)mobileNum
{
/**
* 手机号码
* 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
* 联通:130,131,132,152,155,156,185,186
* 电信:133,1349,153,180,189
*/
NSString* MOBILE= @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
/**
* 中国移动:China Mobile
* 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
*/
NSString* CM= @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
/**
* 中国联通:China Unicom
* 130,131,132,152,155,156,185,186
*/
NSString* CU= @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
/**
* 中国电信:China Telecom
* 133,1349,153,180,189
*/
NSString* CT= @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
/**
* 大陆地区固话及小灵通
* 区号:010,020,021,022,023,024,025,027,028,029
* 号码:七位或八位
*/
// NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE];
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CM];
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CU];
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",CT];
if(([regextestmobile evaluateWithObject:mobileNum] == YES)
|| ([regextestcm evaluateWithObject:mobileNum] == YES)
|| ([regextestct evaluateWithObject:mobileNum] == YES)
|| ([regextestcu evaluateWithObject:mobileNum] == YES))
{
return YES;
}
else
{
return NO;
}
}
【3】邮箱验证(网络转载,未验证)
-(BOOL)validateEmail:(NSString*)email
{
if((0 != [email rangeOfString:@"@"].length) &&
(0 != [email rangeOfString:@"."].length))
{
NSCharacterSet* tmpInvalidCharSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
NSMutableCharacterSet* tmpInvalidMutableCharSet = [[tmpInvalidCharSet mutableCopy] autorelease];
[tmpInvalidMutableCharSet removeCharactersInString:@"_-"];
//使用compare option 来设定比较规则,如
//NSCaseInsensitiveSearch是不区分大小写
//NSLiteralSearch 进行完全比较,区分大小写
//NSNumericSearch 只比较定符串的个数,而不比较字符串的字面值
NSRange range1 = [email rangeOfString:@"@"
options:NSCaseInsensitiveSearch];
//取得用户名部分
NSString* userNameString = [email substringToIndex:range1.location];
NSArray* userNameArray = [userNameString componentsSeparatedByString:@"."];
for(NSString* string in userNameArray)
{
NSRange rangeOfInavlidChars = [string rangeOfCharacterFromSet: tmpInvalidMutableCharSet];
if(rangeOfInavlidChars.length != 0 || [string isEqualToString:@""])
return NO;
}
NSString *domainString = [email substringFromIndex:range1.location+1];
NSArray *domainArray = [domainString componentsSeparatedByString:@"."];
for(NSString *string in domainArray)
{
NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet:tmpInvalidMutableCharSet];
if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
return NO;
}
return YES;
}
else // no ''@'' or ''.'' present
return NO;
}
BOOL NSStringIsValidEmail(NSString *checkString)
{
NString *stricterFilterString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSString *laxString = @".+@.+\.[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
iOS代码片段库
原创
©著作权归作者所有:来自51CTO博客作者TinmKing的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
幸狐 代码片段赏析
幸狐 代码片段赏析
引脚 属性设置 初始化 -
Spring代码片段
文章目录set方法使用xml让spring创建beanJdbcTemplatespring产生JdbcTemplate对象基于XML的事务控制基于注解的事务控制自定义的bean用注解,非自
spring mybatis mysql java aop -
CSS代码片段
居中问题 定位: 将元素居中 将元素水平居中 将元素垂直居中 样式: 文字毛玻璃效果 代码 将元素居中: 1.使
垂直居中 绝对定位 毛玻璃效果