博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一些常见的工具方法
阅读量:6084 次
发布时间:2019-06-20

本文共 3931 字,大约阅读时间需要 13 分钟。

  hot3.png

#pragma mark -- 获取手机系统+ (NSString *)getSystemVersion {   NSString *phoneVersion = [[UIDevice currentDevice] systemVersion];   return phoneVersion;}
#pragma mark -- 获取当前appname+ (NSString *)appName{    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];    return app_Name;}
#pragma mark -- 获取当前appVersion+ (NSString *)appVersion{    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];    return app_Version;}
#pragma mark -- 获取当前Verison+ (NSString *)appBuild {   NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];   return build;}
#pragma mark -- 存储大小+ (CGFloat)totalDiskSpace {    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];    NSNumber *folderSize = [fattributes objectForKey:NSFileSystemSize];    float sizeM = [folderSize floatValue] /1024.0/1024.0;    return sizeM;}
#pragma mark -- 可用存储大小+ (CGFloat)freeDiskSpace {    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];    NSNumber *folderSize = [fattributes objectForKey:NSFileSystemFreeSize];    float sizeM = [folderSize floatValue] /1024.0/1024.0;    return sizeM;}
//根据高度度求宽度  text 计算的内容  Height 计算的高度 font字体大小+ (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font{        CGRect rect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, height)                                     options:NSStringDrawingUsesLineFragmentOrigin                                  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}                                     context:nil];    return rect.size.width;}
///获取文字高度+ (CGFloat)getHeightWithText:(NSString *)text width:(CGFloat)textWidth fontSize:(UIFont *)font{            NSDictionary *dict = @{NSFontAttributeName:font};    CGRect rect = [text boundingRectWithSize:CGSizeMake(textWidth, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];    //返回计算出的行高    return rect.size.height;}
///单数设置组件的上下左右边框+ (void)setBorderWithView:(UIView *)view top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:(UIColor *)color borderWidth:(CGFloat)width{    if (top) {        CALayer *layer = [CALayer layer];        layer.frame = CGRectMake(0, 0, view.frame.size.width, width);        layer.backgroundColor = color.CGColor;        [view.layer addSublayer:layer];    }    if (left) {        CALayer *layer = [CALayer layer];        layer.frame = CGRectMake(0, 0, width, view.frame.size.height);        layer.backgroundColor = color.CGColor;        [view.layer addSublayer:layer];    }    if (bottom) {        CALayer *layer = [CALayer layer];        layer.frame = CGRectMake(0, view.frame.size.height - width, view.frame.size.width, width);        layer.backgroundColor = color.CGColor;        [view.layer addSublayer:layer];    }    if (right) {        CALayer *layer = [CALayer layer];        layer.frame = CGRectMake(view.frame.size.width - width, 0, width, view.frame.size.height);        layer.backgroundColor = color.CGColor;        [view.layer addSublayer:layer];    }}
///获取HTML标签中的信息+ (NSString *)filterHTML:(NSString *)html{    NSDictionary *dic = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};    NSData *data = [html dataUsingEncoding:NSUnicodeStringEncoding];    NSAttributedString *attriStr = [[NSAttributedString alloc] initWithData:data options:dic documentAttributes:nil error:nil];    NSString *str = attriStr.string;    str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@" "];    return str;    }

 

转载于:https://my.oschina.net/rainwz/blog/2872580

你可能感兴趣的文章
java中简单集合框架(二)
查看>>
函数返回局部变量的一些问题
查看>>
Solaris11性能监控--处理器
查看>>
内存模型
查看>>
如何快速开发网站?
查看>>
tomcat等服务器返回给页面的数字分别表示的意思!
查看>>
我的友情链接
查看>>
个人博客
查看>>
我的友情链接
查看>>
mysql 参数 innodb_flush_log_at_trx_commit
查看>>
Windows Server 2012 远程桌面,你需要具有通过远程桌面服务进行登录的权限
查看>>
Linux流量监控工具 – iftop
查看>>
【VMCloud云平台】SCCM(八)OSD(四)
查看>>
JavaTM Virtual Machine Profiler Interface (JVMPI)
查看>>
使用IKAnalyzer分词计算文章关键字并分享几个分词词典
查看>>
分布式进程管理
查看>>
Python下用List对员工信息表进行模糊匹配
查看>>
Mysql 主从复制
查看>>
【SQL Server备份恢复】数据库还原
查看>>
Angular js http请求发送和jquery的ajax一样的数据设置方式
查看>>