我正在尝试以编程方式创建包含 UIImageView 的 UIScrollView。 UIImageView 的图像应该垂直滚动,我的问题是 UIScrollView 从未添加到我的主视图中。 这是代码
@property (strong, nonatomic) UIImageView *advertiseView;
@property UIScrollView *sv;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_sv = [[UIScrollView alloc] init];
_advertiseView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,568)];
UIImage *image = [UIImage imageNamed:@"abc.png"];
_advertiseView.image = image;
_advertiseView.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=image.size};
[_sv addSubview:_advertiseView];
_sv.contentSize = CGSizeMake(320,1136); // size of abc.png
[self.view addSubview:_sv];
}
我错过了什么??
最佳答案
您没有设置 ScrollView 的大小。试试这个:
_sv = [[UIScrollView alloc] initWithFrame:self.view.bounds];
关于ios - 以编程方式将 UIImageView 添加到 UIScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24230061/