ContentMode scaleAspectToFit 不起作用
我有3个观点。 1. 这是主视图,包含其他两个视图。 2. 这是一个比第一个更大的视图。 3. 它包含在第二个视图中。
我想将第二个(显然是第三个)的大小调整为第一个视图的大小,保持纵横比。我尝试将此结果设置 contentMode 为scaleToAspectFitt,但它不起作用。
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
yellowView.autoresizesSubviews = YES;
yellowView.backgroundColor = [UIColor yellowColor];
yellowView.autoresizesSubviews = YES;
yellowView.contentMode = UIViewContentModeScaleAspectFit;
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0,0,350,400)];
blueView.autoresizesSubviews = YES;
blueView.contentMode = UIViewContentModeScaleAspectFit;
blueView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIView *darkView = [[UIView alloc] initWithFrame:CGRectMake(200, 100, 40, 40)];
darkView.backgroundColor = [UIColor blackColor];
darkView.contentMode = UIViewContentModeScaleAspectFit;
darkView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[blueView addSubview:darkView];
[yellowView addSubview:blueView];
[self.view addSubview:yellowView];
[yellowView setNeedsLayout];
[darkView release];
[blueView release];
[yellowView release];
I have 3 views.
1. It's the main view and it contains the other two views.
2. It's a view that is bigger than the first.
3. It's is contained by the second view.
I want to resize the second (and obviously the third) to the size of the first view maintaining aspect ratio. I try to get this result setting contentMode to scaleToAspectFitt but it doesn't work.
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
yellowView.autoresizesSubviews = YES;
yellowView.backgroundColor = [UIColor yellowColor];
yellowView.autoresizesSubviews = YES;
yellowView.contentMode = UIViewContentModeScaleAspectFit;
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0,0,350,400)];
blueView.autoresizesSubviews = YES;
blueView.contentMode = UIViewContentModeScaleAspectFit;
blueView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIView *darkView = [[UIView alloc] initWithFrame:CGRectMake(200, 100, 40, 40)];
darkView.backgroundColor = [UIColor blackColor];
darkView.contentMode = UIViewContentModeScaleAspectFit;
darkView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[blueView addSubview:darkView];
[yellowView addSubview:blueView];
[self.view addSubview:yellowView];
[yellowView setNeedsLayout];
[darkView release];
[blueView release];
[yellowView release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里我改变了一个这样的视图 - 你必须修改你的所有视图
Here I changed for one view like this - you have to modify all your views