Resize view borders to fit a frame

Now my situation is that I am trying to resize a label, I can resize it with UIPinchGestureRecognizer

, but what that does only resizes the frame.

func handleScale(recognizer: UIPinchGestureRecognizer)
{

    recognizer.view!.transform = CGAffineTransformScale(recognizer.view!.transform,
        recognizer.scale, recognizer.scale)
    recognizer.scale = 1

    recognizer.view!.frame = CGRectMake(recognizer.view!.frame.minX,recognizer.view!.frame.minY, recognizer.view!.frame.width, recognizer.view!.frame.height)  
}   

      

I want to be able to change the borders of the label so that the text appears again at the new frame sizes. I tried to only resize the marks in the scale, but it doesn't work as expected.

I made a button on click, it sets the borders of the labels to match the border of the labels. Though it doesn't seem to work.

    label.bounds = CGRectMake(0, 0, CGRectGetWidth(self.label.frame), CGRectGetHeight(self.label.frame))

      

What it does is change it to a different coordinate and then to a frame.

These are the print logs from the button action:

Frame Before(-54.2193053279009,279.213449112017,513.438610655802,85.5731017759669)
Bounds Before(0.0,0.0,300.0,50.0)
label.bounds = CGRectMake(0, 0, CGRectGetWidth(self.label.frame), CGRectGetHeight(self.label.frame))
Frame After(-236.8653448536,248.7724425244,878.7306897072,146.4551149512)
Bounds After(0.0,0.0,513.438610655802,85.5731017759669)

      

What it does is after the borders are set, it changes the frame values. Does anyone know how to fix this?

I tried to set the frame from previous frame values ​​but still doesn't work.

+3


source to share


1 answer


You are using the script described in the documentation forUIView

setTransform:

:

WARNING

If this property is not an identity transform, the value of the frame property is undefined and should therefore be ignored.



If your goal is simply to visually shrink the label, just apply the transform without adjusting the border.

If you intend to shrink the label's geometric rectangle while keeping the text size the same, you can create a new frame with CGRectApplyAffineTransform(CGAffineTransformMakeScale(recognizer.scale, recognizer.scale))

. If you find that your text is still not updating, try calling setNeedsLayout

or setNeedsDisplay

on the shortcut (depending on how its drawing is handled).

+1


source







All Articles