UILable numberoflines and font size automatically

2019-08-02 18:55发布

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

enter image description here ******** Image 1 *****************

enter image description here ******** Image 2 *****************

enter image description here ******** Image 3 *****************

Thanks in Advance ..

2条回答
够拽才男人
2楼-- · 2019-08-02 19:33

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.

查看更多
冷血范
3楼-- · 2019-08-02 19:44

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.

查看更多
登录 后发表回答