简体   繁体   中英

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). 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

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/

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:

Make UILabels as subview to 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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