以下是這種情況:我有一個VC裏面有一個Custom UIView。這個自定義UIView有一個.xib文件,其中包含2個UIImageViews。我試圖通過使用AutoLayout讓這兩個UIImageView在不同的屏幕尺寸上縮放到相同的尺寸。然而,當我啓動我的應用程序時,我的Custom UIView中的圖像超出了Custom UIView的超級視圖(這是VC)容器大小的界限。請幫忙。這裏有一些圖片可以更詳細地解釋問題。使用.xib文件和AutoLayout自定義UIView調整UIImageViews的尺寸
我的代碼在自定義的UIView: @implementation CustomTwoImagesSelectedUIView
-(id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self load];
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self load];
}
return self;
}
- (void)load {
[[NSBundle mainBundle] loadNibNamed:@"CustomTwoImagesSelectedUIView" owner:self options:nil];
self.lastImageView.layer.cornerRadius = 5.0f;
self.lastImageView.clipsToBounds = YES;
self.secondToLastImageView.layer.cornerRadius = 5.0f;
self.secondToLastImageView.clipsToBounds = YES;
[self addSubview:self.twoImagesSelectedView];
}
我通過擺脫xib文件解決了這個問題,並關注了main.storyboard上的自動佈局約束。我很欣賞答案。 – ddeger 2015-03-26 03:33:21