简体   繁体   English

如何随着字体大小变化动态平滑地增加和减少UILabel的文本

[英]How to dynamically increase and decrease UILabel's text smoothly as font size varies ios

I have tried searching this functionality but didn't solved my problem. 我尝试搜索此功能,但没有解决我的问题。

What I Want: I have a UILabels text as "attended" with initial font size of 28 (totally four labels with different fonts sizes and texts). 我想要的是:我有一个UILabels文本为“有人看管”,初始字体大小为28(总共四个标签,它们的字体大小和文字不同)。 Now I vary slider (which is placed in the bottom), I will send the font size to be increased or increased. 现在,我改变滑块(位于底部),我将发送要增大或增大的字体大小。 Now, i want to not only change the font size but also UILabel frame like 现在,我不仅要更改字体大小,还要更改UILabel框架,例如

self.labelAttendCount.frame = CGRectMake(40 + (diff * 0.7) , 110 - (diff * 0.3), 40 - diff/5, 30 - (diff * 0.3))
self.labelAttendCount.font = UIFont(name: "ArialMT", size: round(28 - (diff * 0.28)))

Everything goes fine but, when its position is changing its jerky (or shaky). 一切都很好,但是当其位置改变时会变得生涩(或不稳定)。 I want this to be dealt smoothly. 我希望这个问题能顺利解决。

refer to this link where there is smooth increase or decrease in label size. 请参阅此链接,其中标签大小可以平滑地增加或减少。 http://macoscope.com/blog/ios-7-dynamic-type-simulator-for-designers/ http://macoscope.com/blog/ios-7-dynamic-type-simulator-for-designers/

Hope u understand my question. 希望你理解我的问题。

Please check this shared video link (removed link) 请检查此共享视频链接(已删除的链接)

This solution might be usefull for some one. 此解决方案可能对某些人有用。

Finally got a Solution to shrink UILabel or UIButton Text and change their position: 最终得到了缩小UILabel或UIButton Text并更改其位置的解决方案:

Make UILabels as subview to UIView. 使UILabels作为UIView的子视图。

    viewLeft.addsubView(labelAttendedCount)

later 后来

    viewLeft.transform = CGAffineTransformMakeScale(1 - (diff * 0.01), 1 - (diff * 0.01)) // to shrink viewLeft UIView
        viewLeft.frame = CGRectMake(25 + (diff * 0.8), 110 - (diff * 0.3), 100 , 50 - diff/2) // to move the ViewLeft and diff is increase in the contentoffset or UIPanGesture location.y
        viewLeft.center = CGPointMake(25 + viewLeft.frame.width/2 + (diff * 0.8), viewLeft.frame.origin.y + viewLeft.frame.height/2)  // To adjust the position of the UIView.

除了改变字体大小,您还可以使用UIView的转换,例如

self.labelAttendCount.transform = CGAffineTransformMakeScale(1.5, 1.5);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM