2
votes

When you resize a UIView, the width/height increases to the right/bottom direction. Is there a way to make it go the opposite directions? I thought this might be something layer.anchorPoint can achieve, but it doesn't look like it.

1
But if you change the x and y of the frame, the direction could be opposite. for example,a rect from (10,10,10,10) to (0,0,20,20). Correct me if i'm wrong.Mat
@Mat Well, it's not exactly opposite, you are repositioning it. I agree the end result is the same. But basically, I am curious if you can achieve in iOS, the equivalent of this CSS style: position:absolute; bottom:0; right:0;. If you resize this element, it goes in the left/top direction.pixelfreak
I'm curious what resize method are you using? Adjusting the frame is the main way I resize things therefore this idea of a view resizing bottom/right is dependant on the caller setting the frame to have that happen.Paul.s

1 Answers

2
votes

The fastest way to do it would be to remake the view's frame.

Say you want to increase it's width and height by 10 in the "opposite" direction.

This would do that.

view.frame = CGRectMake(view.frame.origin.x - 10, view.frame.origin.y - 10, view.frame.size.width + 10, view.frame.size.height + 10);

You might put this in a method to make it easier:

-(void)inverseResizeView(UIView *)view width:(int)deltaWidth height:(int)deltaHeight{
   view.frame = CGRectMake(view.frame.origin.x - deltaWidth, view.frame.origin.y - deltaHeight, view.frame.size.width + deltaWidth, view.frame.size.height + deltaHeight);
}