简体   繁体   中英

UILabel text scaling, Programmatically?

I want to change my UILabel text or UILabel itself's size by using UISlider , I know it's something we don't do it for an normal application. But basically I am trying new and different things to explore Objective -C language and iOS platform.

So far I am able to change colour of a font by UISlider , Which looks really great, So thought of changing it's size too by UISlider . Below I am posting pictures to clarify my thoughts visually!

From -----> 在此处输入图片说明 To -------> 在此处输入图片说明

While making those images I realised I might have to change size of UILable and Size of font too. Am I right? Is this possible?

its quite simple actually

According to slider change value dynamically increase height and width of your label..

有许多方法可以解决此问题,一种方法是仅使用滑块更改字体大小,然后在更改字体时使用sizeWithFont:NSString的实例方法计算帧大小。

textLabel.font = [UIFont boldSystemFontOfSize:slider.value];    
CGSize newSize = [textLabel.text sizeWithFont:textLabel.font];    

This should make it
an alternative is to set the fram of the label above the complete size above the textField and set textAlignement = center

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