Ios UIScrollview分页中的页面大小不正确
我正在尝试使用UIScrollview进行简单的分页,但是在第二个屏幕之后,页面就被删除了。这是我的密码Ios UIScrollview分页中的页面大小不正确,ios,objective-c,xcode,uiscrollview,paging,Ios,Objective C,Xcode,Uiscrollview,Paging,我正在尝试使用UIScrollview进行简单的分页,但是在第二个屏幕之后,页面就被删除了。这是我的密码 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSArray *colors =[NSArray arrayWithObjects:@"1. This is my first Page ",@"2. This i
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
NSArray *colors =[NSArray arrayWithObjects:@"1. This is my first Page ",@"2. This is my Second Page",@"3. This is my third Page",@"4. This is my fourth Page",@"5. This is my fifth Page",nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = (scroll_events.frame.size.width) * i;
frame.origin.y = 0;
frame.size = scroll_events.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
[self.scroll_events addSubview:subview];
UITextView *myTextView = [[UITextView alloc] init];
myTextView.text = colors[i];
[subview addSubview:myTextView];
[myTextView setBackgroundColor: [UIColor redColor]];
[myTextView setTextColor: [UIColor blackColor]];
[myTextView setFont: [UIFont fontWithName:@"Lobster 1.4" size:30]];
myTextView.frame = CGRectMake(0.0,0.0,scroll_events.bounds.size.width,scroll_events.bounds.size.height);
myTextView.editable = NO;
myTextView.selectable = NO;
myTextView.scrollEnabled = NO;
}
self.scroll_events.contentSize = CGSizeMake(self.scroll_events.frame.size.width * colors.count, self.scroll_events.frame.size.height);
}
-(void)viewDidLoad{
[超级视图下载];
//加载视图后执行任何其他设置。
NSArray*colors=[NSArray ARRAY WITH OBJECTS:@“1.这是我的第一页”,“2.这是我的第二页”,“3.这是我的第三页”,“4.这是我的第四页”,“5.这是我的第五页”,无];
对于(int i=0;i
这是ViewDidLoad中我的滚动视图的屏幕截图,可能您的滚动视图的框架尚未设置 在ViewDidDisplay中尝试该代码并检查其是否有效 建议:您应该对UISCrollView进行子类化,并在那里初始化视图,而不是在ViewController中 让我知道它起作用了 问候