判断字符串是否是中文的代码
- (BOOL)isChinese:(NSString *)text
{
NSString *temp =@"[\u4e00-\u9fa5]";
NSRange range = [textrangeOfString:tempoptions:NSRegularExpressionSearch];
return range.location !=NSNotFound ?YES :NO;
}
iOS 隐藏/去掉 导航栏返回按钮中的文字
[[UIBarButtonItemappearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
forBarMetrics:UIBarMetricsDefault];
iOSMD5加密数据方法
+ (NSString *)md5StringFromString:(NSString *)string {
if(string ==nil || [stringlength] == 0)
returnnil;
const char *value = [stringUTF8String];
unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
CC_MD5(value, (CC_LONG)strlen(value), outputBuffer);
NSMutableString *outputString = [[NSMutableStringalloc]initWithCapacity:CC_MD5_DIGEST_LENGTH *2];
for(NSInteger count =0; count <CC_MD5_DIGEST_LENGTH; count++){
[outputString appendFormat:@"%02x",outputBuffer[count]];
}
return outputString;
}
iOS内获取当前APP版本号+ (NSString *)appVersionString {
return [[[NSBundlemainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"];
}
- (void)initUserInterface { UILabel *label = [[UILabel alloc]init]; label.numberOfLines = 0; // 需要把显示行数设置成无限制 label.font = [UIFont systemFontOfSize:15]; label.textAlignment = NSTextAlignmentCenter; label.text = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; CGSize size = [self sizeWithString:label.text font:label.font]; label.bounds = CGRectMake(0, 0, size.width, size.height); label.center = self.view.center; [self.view addSubview:label]; } // 定义成方法方便多个label调用 增加代码的复用性 - (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font { CGRect rect = [string boundingRectWithSize:CGSizeMake(320, 8000)//限制最大的宽度和高度 options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading |NSStringDrawingUsesLineFragmentOrigin//采用换行模式 attributes:@{NSFontAttributeName: font}//传人的字体字典 context:nil]; return rect.size; }
// 在TableView 里的子视图固定 不随滑动而改变
myView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 150, 30)];
myView.backgroundColor = [UIColor redColor];
[self.tableView addSubview:myView];
在代理方法里设置自身的y值+contentOffset.y
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
myView.frame = CGRectMake(myView.frame.origin.x, 100+self.tableView.contentOffset.y , myView.frame.size.width, myView.frame.size.height);
}