UILable numberoflines and font size automatically set during zoom in out time

爷,独闯天下 提交于 2019-12-24 17:04:52

问题


My requires is as below.

i have a added UILable inside UIView width & height is 30. i have set UIPinchGestureRecognizer to that UIView. Pinch in out functionality is working fine with UIView.

But my i want that when i zoom in UILable font size and numberOfLine automatically set in that UIView.

So at initial UILable not visible in View. When i Zoom in that time UILable get the are to display text so than UILable will be visible (ex. This time in 3 line). If i increase the Zoom level than text will be display in one row.

how can archive this functionality ?

See the below screenshot What i want to do

******** Image 1 *****************

******** Image 2 *****************

******** Image 3 *****************

Thanks in Advance ..


回答1:


See this: resize all subview in scrollViewDidZoom On scrollViewDidZoom you can set the font size proportionally to zoomScale. I would suggest to set numberOfLines to 0 on label, but of course you can set it manually too when zooming in/out.




回答2:


You can use the delegate to detect when the zoom changes, and make your label visible then:

- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
     if (scrollView.zoomScale > minimunScaleToShowZoom)
     {
         myLabel.hidden = NO;
     }
     else
     {
        myLabel.hidden = YES;
     }
}

Play with different values for minimunScaleToShowZoom and check which one suits you.



来源:https://stackoverflow.com/questions/19728213/uilable-numberoflines-and-font-size-automatically-set-during-zoom-in-out-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!