iOS 字符串的宽度和高度自适应
2024-09-14 00:34:27
//获取字符串的宽度
-(float)widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
{
UIColor *backgroundColor=[UIColor blackColor];
UIFont *font=[UIFont boldSystemFontOfSize:fontSize];
CGRect sizeToFit = [value boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
NSForegroundColorAttributeName:backgroundColor,
NSFontAttributeName:font
} context:nil]; return sizeToFit.size.width;
}
//获得字符串的高度
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
UIColor *backgroundColor=[UIColor blackColor];
UIFont *font=[UIFont boldSystemFontOfSize:18.0];
CGRect sizeToFit = [value boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
NSForegroundColorAttributeName:backgroundColor,
NSFontAttributeName:font
} context:nil];
return sizeToFit.size.height;
}
最新文章
- 特殊文件: /dev/null和/dev/tty
- [转]Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)
- 入手《C#入门经典(第6版)》,据说今天是读书日
- object.assign()方法的使用
- win7(X64)+VS2013+OpenCV3.1环境配置
- Why you have so few friends?
- C#路径/文件/目录/I/O常见操作汇总<;转载>;
- 使用iTextSharp来填充PDF模板文件
- Linux下生产者与消费者的线程实现
- [c#]如何在form的webbrowser控件中获得鼠标坐标
- iOS socket 实现tcp和服务器长链接的简单使用心得
- couldn&#39;t connect to the device trackpad
- C#属性总结
- CocoaPods安装和使用及问题----看过写的最好的
- .NetCore+Jexus代理+Redis模拟秒杀商品活动
- Selenium 定位网页元素
- Linux指令--traceroute,netstat,ss
- 我所知道的window.location
- 无代理处理post非简单请求跨域问题
- IDEA 破解
热门文章
- 2000条你应知的WPF小姿势 基础篇<;1-7>;
- Egret3D研究报告(二)从Unity3D导出场景到Egret3D
- android内部培训视频_第四节(1)_异步网络操作
- ASP.NET MVC中利用AuthorizeAttribute实现访问身份是否合法以及Cookie过期问题的处理
- TODO:Github的使用技巧之同步代码
- 特殊的数据类型: bit、sql_variant、sysname
- 解析大型.NET ERP系统 数据审计功能
- DDD实践切入点(一)
- CRL2.3(ORM开发框架)源码github发布
- JS组件系列——Bootstrap文件上传组件:bootstrap fileinput