Giter VIP home page Giter VIP logo

Comments (2)

youngsoft avatar youngsoft commented on May 25, 2024

这是一个好问题,在一些场景中我们希望UILabel在某个固定的宽度下高度能够自适应而换行,所以我们可以按照下面的写法:

 labelView.tg_width.equal(100)
 labelView.tg_height.equal(.wrap)

而要想让UILabel的高度在某个固定宽度下自适应时就必须将numberOfLines的值设置为0。当时的一个纠结的点是否要在设置高度自适应时将numberOfLines的设置权交给使用方还是库里面自己就处理了:

  1. 如果交给使用方那么在设置tg_height.equal(.wrap)后使用方还要明确的设置一下numberOfLines = 0. 这样就增加了使用的成本。
  2. 如果是库内部设置的话,这样就会向使用方隐藏了一些未可知的设置。

所以综合考虑,为了易用性还是选择了后者。其实这个问题也还好理解,如果你想要你的高度自适应而且会换行那么你只要设置明确的宽度和为wrap的高度即可,这时候系统会自动换行;而如果你想让你的高度和宽度也同时自适应时,你可以设置宽度和高度都为wrap,这样即使内部设置了numberOfLines为0也不会有换行的处理;而如果你就想让宽度占用剩余的空间,但是高度不换行那么你就不应该设置高度为.wrap,而是应该明确的指定一个高度值。

from tangramkit.

EkkoG avatar EkkoG commented on May 25, 2024

OK 了解了,不过觉得交给使用方比较直观,有没有设置自己心里清楚,内部修改会导致使用方比较困惑为什么明明没有设置怎么就换行了

from tangramkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.