Dynamically changing background color of a UIView

Posted by EricM on Stack Overflow See other posts from Stack Overflow or by EricM
Published on 2010-05-24T19:50:32Z Indexed on 2010/05/24 20:21 UTC
Read the original article Hit count: 287

Filed under:
|
|

Hello-

Here's my setup. I have a viewcontroller that I'm creating and adding as a subview. The viewcontroller presents some options that a user can chose from. The viewcontroller is being pushed in response to a "long press" gesture. Within the viewcontroller, I added a child UIView to group some other controls together so I can move them around the screen as a unit and, when they are displayed, center them on the location of the long press. Here is the code that instantiates the view controller, changes its location, and adds it as a subview:

UserOptions *opts = [[UserOptions alloc] initWithNibName:@"UserOptions" bundle:nil];
[opts recenterOptions:location];
[self.view addSubview:opts.view];

That bit of code does create and push the viewcontroller, but the call to recenterOptions doesn't do anything. Here is that method:

- (void) recenterOptions:(CGPoint)location {
    CGRect oldFrame = self.optionsView.frame;

    CGFloat newX = location.x; // + oldFrame.size.width / 2.0;
    CGFloat newY = location.y; // + oldFrame.size.height / 2.0;

    CGRect newFrame = CGRectMake(newX, newY, oldFrame.size.width, oldFrame.size.height);

    self.optionsView.frame = newFrame;
}

Note that self.optionsView is the child UIView that I added to the viewcontroller's nib.

Does anyone know why I'm unable to change the location of the UIView?

Regards, Eric

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c