当前位置:网站首页>根据高度计算文字大小
根据高度计算文字大小
2022-04-22 23:52:00 【~废弃回忆 �༄】
@implementation UILabel (****)
/** * @brief 计算文字的大小 * * @param font 字体(默认为系统字体) * @param height 约束高度 */
- (CGSize)sizeWithFont:(UIFont *)font constrainedToHeight:(CGFloat)height
{
UIFont *textFont = font ? font : [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGSize textSize;
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 70000
if ([self respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]) {
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attributes = @{
NSFontAttributeName: textFont,
NSParagraphStyleAttributeName: paragraph};
textSize = [self boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height)
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingTruncatesLastVisibleLine)
attributes:attributes
context:nil].size;
} else {
textSize = [self sizeWithFont:textFont
constrainedToSize:CGSizeMake(CGFLOAT_MAX, height)
lineBreakMode:NSLineBreakByWordWrapping];
}
#else
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
NSDictionary *attributes = @{
NSFontAttributeName: textFont,
NSParagraphStyleAttributeName: paragraph};
textSize = [self.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height)
options:(NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingTruncatesLastVisibleLine)
attributes:attributes
context:nil].size;
#endif
return CGSizeMake(ceil(textSize.width), ceil(textSize.height));
}
@end
版权声明
本文为[~废弃回忆 �༄]所创,转载请带上原文链接,感谢
https://blog.csdn.net/eastWind1101/article/details/117434785
边栏推荐
- Solve the error reporting problem of require is not defined
- Typora樣式調優
- [dvcon2020] adopt advanced save & restore technology to accelerate simulation turnaround time
- 程序设计语言基础(1)
- [dvcon2020] automatic generation method of UVM sequence based on ral
- Use example to add a sort invalidation problem when using PageHelper
- 【Pygame小游戏】Chrome上的小恐龙竟可以用代码玩儿了?它看起来很好玩儿的样子~
- Reg 正则表达式学习笔记
- [perseverance challenge] PCIe asks and answers every day (filed on March 2022)
- Invite you to participate in the ume plug-in development competition
猜你喜欢

MySQL索引的语法是什么

【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)

visual studio 2019恢复默认设置

Django指定数据库的时候报No module named ‘django_test.settings‘

Introduction to opencv (II) -- affine transformation and perspective transformation

共轭梯度法(Conjugate Gradients)(4)
![[dvcon2020] acceleration of low power design level verification based on signoff abstract model](/img/c1/3495627bf41f5ba8b06d624831e6d8.png)
[dvcon2020] acceleration of low power design level verification based on signoff abstract model
![FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决](/img/72/dca1064713646f909c4a7a8567a742.png)
FileNotFoundError: [Errno 2] No such file or directory: 'image/1.jpg'问题解决
![[newcoder] week 20220422](/img/cd/3d24d3b5be26166ab94742da8c46dd.png)
[newcoder] week 20220422

unbuntu18.04 安装 gamit10.71 problem solution
随机推荐
Install vs2017 plug-in glsl language integration V0 under Windows 7 10.120. Vsix reported an error: Microsoft visualc. redist. twelve
[PCIe 6.0] new features of PCIe 6.0 - detailed explanation of l0p
SystemVerilog verification - Test Platform preparation guide learning notes (2): process statements and subroutines
STM32F103 independent watchdog
FPGA (VI) RTL code II (complex circuit design 1)
Typora style tuning
2022 hard plus deshmann annual summit: release of a variety of pilot flagship to lead the high-end market
MPP architecture concept
Write a Tetris game in C language
Online fox U3D client game configuration loading failed couldn't connect to server
Vscode uses emmylua plug-in to debug unity project tolua code
Method of shrinking master-slave nodes in redis cluster cluster
Vs-写汇编
SystemVerilog verification - Test Platform preparation guide learning notes (5): function coverage
[leetcode] binary tree, maximum depth of 104 binary tree, diameter of 543 binary tree, maximum path and sum of 124 binary tree
[leetcode] binary tree, 226 flip the binary tree, 116 fill in the right pointer of the binary tree node, and 114 expand the binary tree into a linked list
Hello, I want to open an account for crude oil futures. How can I open an account for futures safely and reliably?
[day22] - [linked list] intersecting linked list
80386 compilation_ Introduction to global description table GDT
[*CTF2022]web题目复现及wp