我正在添加一个带有UIImage的UIImageView,希望它出现在主UIView的中心顶部。
我将使用UIPageControl将该视图向左滑动并从右侧带入新视图。我已经添加了UIImageView,通常只会将其添加到右下角。
-(void)createUIViews{
UIImage *image1 = [UIImage imageNamed:@"GiftCard.png"];
firstView = [[UIImageView alloc] initWithImage:image1];
firstView.backgroundColor = [UIColor grayColor];
firstView.tag = 1;
firstView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
}
现在,我希望将它放置在顶部中心。所以我想到了这样的东西:
CGRect newFrame = self.view.frame;
newFrame.origin.x += 50;
self.view.frame = newFrame;
[self.view addSubview:firstView];
但是当我在之前的代码底部添加这段代码时(顺便说一下,这段代码是从viewDidLoad调用的),图片仍然出现在右下角。我该如何正确定位它?