1.计算字符串高度
iOS6中的方法:
CGSize sizeTofit = [str sizeWithFont:[UIFont fontWithName:MPFONTNAME size:16] forWidth: 100 lineBreakMode:NSLineBreakByWordWrapping];
iOS7中方法:
CGRect tmpRect = [str boundingRectWithSize:CGSizeMake(100,MAXFLOAT)options:NSStringDrawingUsesLineFragmentOriginattributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:MPFONTNAME size:16],NSFontAttributeName,nil]context:nil];
headerHeight= tmpRect.size.height;
2.字符串中是否含有中文
+ (BOOL)checkIsChinese:(NSString *)string
{
for(int i=0; i<string.length; i++){
unichar ch = [string characterAtIndex:i];
if(0x4E00<= ch && ch <=0x9FA5)
{
return YES;
}
}
return NO;
}
3.去除空格和回车
(1)去除两端空格
NSString *temp = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
(2)去除两端空格和回车
NSString *text = [temp stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
4.获取汉字的拼音
- (NSString*)transform:(NSString*)chinese
{
//将NSString装换成NSMutableString
NSMutableString*pinyin = [chinese mutableCopy];
//将汉字转换为拼音(带音标)
CFStringTransform((__bridge CFMutableStringRef)pinyin,NULL,kCFStringTransformMandarinLatin,NO);
NSLog(@"%@", pinyin);
//去掉拼音的音标
CFStringTransform((__bridge CFMutableStringRef)pinyin,NULL,kCFStringTransformStripCombiningMarks,NO);
NSLog(@"------%@--------", pinyin);
//返回最近结果
return pinyin;
}
5.将字符串title复制到剪贴板
UIPasteboard*pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string= title;
网友评论