backslash-f

SO thread: http://bit.ly/setFontSizeToFillUILabelHeight

Dec 19th, 2014
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. ####
  2. ## Adjusting font size according to the height of an UILabel.
  3. ## For more details, refer to this Stack Overflow thread:
  4. ## http://bit.ly/setFontSizeToFillUILabelHeight
  5. ####
  6.  
  7. minFontSize: 18.0
  8. maxFontSize: 67.0
  9. fontSizeAverage: 0.0
  10. textAndLabelHeightDiff: 0.0
  11.  
  12. ### Iteration number: 1 ###
  13.  
  14. minFontSize: 18.0
  15. maxFontSize: 67.0
  16. fontSizeAverage: 42.5
  17. labelText: $0.99
  18. labelHeight: 40.5
  19. testStringHeight: 42.5
  20. textAndLabelHeightDiff: -2.0
  21. maxFontSize: 41.5
  22.  
  23. ### Iteration number: 2 ###
  24.  
  25. minFontSize: 18.0
  26. maxFontSize: 41.5
  27. fontSizeAverage: 29.75
  28. labelText: $0.99
  29. labelHeight: 40.5
  30. testStringHeight: 29.75
  31. textAndLabelHeightDiff: 10.75
  32. minFontSize: 30.75
  33.  
  34. ### Iteration number: 3 ###
  35.  
  36. minFontSize: 30.75
  37. maxFontSize: 41.5
  38. fontSizeAverage: 36.125
  39. labelText: $0.99
  40. labelHeight: 40.5
  41. testStringHeight: 36.125
  42. textAndLabelHeightDiff: 4.375
  43. minFontSize: 37.125
  44.  
  45. ### Iteration number: 4 ###
  46.  
  47. minFontSize: 37.125
  48. maxFontSize: 41.5
  49. fontSizeAverage: 39.3125
  50. labelText: $0.99
  51. labelHeight: 40.5
  52. testStringHeight: 39.3125
  53. textAndLabelHeightDiff: 1.1875
  54. minFontSize: 40.3125
  55.  
  56. ### Iteration number: 5 ###
  57.  
  58. minFontSize: 40.3125
  59. maxFontSize: 41.5
  60. fontSizeAverage: 40.9062
  61. labelText: $0.99
  62. labelHeight: 40.5
  63. testStringHeight: 40.9062
  64. textAndLabelHeightDiff: -0.40625
  65. maxFontSize: 39.9062
  66. Returned font with size: <UICTFont: 0x7a663920> font-family: "ProximaNovaCond-Black"; font-weight: bold; font-style: normal; font-size: 40.91pt
  67. minFontSize: 18.0
  68. maxFontSize: 67.0
  69. fontSizeAverage: 0.0
  70. textAndLabelHeightDiff: 0.0
  71.  
  72. ### Iteration number: 1 ###
  73.  
  74. minFontSize: 18.0
  75. maxFontSize: 67.0
  76. fontSizeAverage: 42.5
  77. labelText: $0.99
  78. labelHeight: 40.5
  79. testStringHeight: 42.5
  80. textAndLabelHeightDiff: -2.0
  81. maxFontSize: 41.5
  82.  
  83. ### Iteration number: 2 ###
  84.  
  85. minFontSize: 18.0
  86. maxFontSize: 41.5
  87. fontSizeAverage: 29.75
  88. labelText: $0.99
  89. labelHeight: 40.5
  90. testStringHeight: 29.75
  91. textAndLabelHeightDiff: 10.75
  92. minFontSize: 30.75
  93.  
  94. ### Iteration number: 3 ###
  95.  
  96. minFontSize: 30.75
  97. maxFontSize: 41.5
  98. fontSizeAverage: 36.125
  99. labelText: $0.99
  100. labelHeight: 40.5
  101. testStringHeight: 36.125
  102. textAndLabelHeightDiff: 4.375
  103. minFontSize: 37.125
  104.  
  105. ### Iteration number: 4 ###
  106.  
  107. minFontSize: 37.125
  108. maxFontSize: 41.5
  109. fontSizeAverage: 39.3125
  110. labelText: $0.99
  111. labelHeight: 40.5
  112. testStringHeight: 39.3125
  113. textAndLabelHeightDiff: 1.1875
  114. minFontSize: 40.3125
  115.  
  116. ### Iteration number: 5 ###
  117.  
  118. minFontSize: 40.3125
  119. maxFontSize: 41.5
  120. fontSizeAverage: 40.9062
  121. labelText: $0.99
  122. labelHeight: 40.5
  123. testStringHeight: 40.9062
  124. textAndLabelHeightDiff: -0.40625
  125. maxFontSize: 39.9062
  126. Returned font with size: <UICTFont: 0x7a663920> font-family: "ProximaNovaCond-Black"; font-weight: bold; font-style: normal; font-size: 40.91pt
Add Comment
Please, Sign In to add comment