ios中给uiscrollview添加的全屏子视图为什么宽度只显示屏幕的一半

2025-05-07 21:34:48
推荐回答(1个)
回答1:

- (void)viewDidLoad
{
[superviewDidLoad];

UIScrollView *tempScroll = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,64,320, 200)];
[tempScrollsetBackgroundColor:[UIColor grayColor]];
[tempScroll setContentSize:CGSizeMake(self.view.bounds.size.width,self.view.bounds.size.height)];
[self.view addSubview:tempScroll];

UIButton*tempButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[tempButtonsetBackgroundColor:[UIColor redColor]];
[tempButton setTitle:@"subView A"forState:UIControlStateNormal];
[tempButtonsetFrame:CGRectMake(80,0,80, 100)];

NSLog(@"%d",tempScroll.subviews.count);
[tempScrolladdSubview:tempButton];
}