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

2025年05月07日 21:34
有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];
}