Reputation: 49
I want an image to automatically align to the top, I figure the only want to do this is through making a frame that positions it that way. After doing some research, I can't seem to figure out why this code doesn't move the image at all... I have substituted many values in the topPadding and leftPadding variables..
- (void)constructImageView:(UIImage *)image {
CGFloat topPadding = 20.f;
CGFloat leftPadding = 30.f;
CGRect frame = CGRectMake(leftPadding, topPadding, image.size.width, image.size.height);
self.imageView = [[UIImageView alloc] initWithFrame:frame];
self.imageView.image = image;
[self addSubview:self.imageView];
}
Upvotes: 0
Views: 44
Reputation: 5775
Are you using Autolayout? If yes, setFrame
: does not work properly with autolayout. If thats the case, then your options are:
self.view.translatesAutoresizingMaskIntoConstraints = YES
Upvotes: 1