Search code examples
ioscgrect

Only changing X axis value


Im aware I can change the position of my image view like this

myImageView.frame = CGRectMake(99, 34, 32, 32);

But how do I change just the x value leave the rest as they are? I realize this is a simple question but because I don't know how to word the search Im having difficulty finding a solution. Thanks


Solution

  • //capture frame
    CGRect thisRect = myImageView.frame;
    
    //modify required frame parameter (.origin.x/y, .size.width/height)
    thisRect.origin.x = 0;
    
    //set modified frame to object
    [myImageView setFrame:thisRect];