Comments (2)
这是一个好问题,在一些场景中我们希望UILabel在某个固定的宽度下高度能够自适应而换行,所以我们可以按照下面的写法:
labelView.tg_width.equal(100)
labelView.tg_height.equal(.wrap)
而要想让UILabel的高度在某个固定宽度下自适应时就必须将numberOfLines的值设置为0。当时的一个纠结的点是否要在设置高度自适应时将numberOfLines的设置权交给使用方还是库里面自己就处理了:
- 如果交给使用方那么在设置tg_height.equal(.wrap)后使用方还要明确的设置一下numberOfLines = 0. 这样就增加了使用的成本。
- 如果是库内部设置的话,这样就会向使用方隐藏了一些未可知的设置。
所以综合考虑,为了易用性还是选择了后者。其实这个问题也还好理解,如果你想要你的高度自适应而且会换行那么你只要设置明确的宽度和为wrap的高度即可,这时候系统会自动换行;而如果你想让你的高度和宽度也同时自适应时,你可以设置宽度和高度都为wrap,这样即使内部设置了numberOfLines为0也不会有换行的处理;而如果你就想让宽度占用剩余的空间,但是高度不换行那么你就不应该设置高度为.wrap,而是应该明确的指定一个高度值。
from tangramkit.
OK 了解了,不过觉得交给使用方比较直观,有没有设置自己心里清楚,内部修改会导致使用方比较困惑为什么明明没有设置怎么就换行了
from tangramkit.
Related Issues (20)
- tg_width以及and() HOT 1
- 布局动画问题 HOT 2
- tg_setSubviews失效
- 你好,我是跟着你的框架学的ios开发,有一个问题想请教一下 HOT 4
- 希望能实现tg_min功能,让视图宽度等于多个视图宽度的最小值,谢谢 HOT 1
- iOS 13 TGBorderline 未适配 Dark Model HOT 1
- 测试环境iOS13, FlowLayout 的 对齐问题 HOT 1
- 在Controller中合适才可以拿到准确的frame? HOT 2
- 【BUG】非布局视图layoutSubviews相关 HOT 1
- 【需求】流动布局`TGFloatLayout`添加动态边距 HOT 1
- 【需求】FlexLayout支持 HOT 1
- 【BUG】布局视图响应事件并未传递 HOT 1
- 请问为什么不更新了 HOT 4
- CELL复用问题 HOT 1
- mach-o包体积过大, 远超snapkit HOT 1
- iOS 15 上 UITableViewCell 自适应 cell 发生某一行加载不出来
- 布局高度问题,希望还能得到作者回复 HOT 4
- 布局高度问题,希望作者解答一下 HOT 14
- There are quite a lot of functions
- iphone 12以上,scrollview中的layout隐藏视图,页面卡死 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tangramkit.