1

我一直在关注一个教程,用于在UIScrollview.

分页与UIScrollview节。

我现在想改变它,而不是一个UIimageview,它显示一个UITextview。在分页时使用不同的文本。

不确定如何实现 textview 而不是 imageview。

有任何想法吗?

谢谢

正在使用的代码:

- (void)loadPage:(NSInteger)page {
    if (page < 0 || page >= self.pageImages.count) {
        // If it's outside the range of what you have to display, then do nothing
        return;
    }

    // 1
    UIView *pageView = [self.pageViews objectAtIndex:page];
    if ((NSNull*)pageView == [NSNull null]) {
        // 2
        CGRect frame = self.scrollView.bounds;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0.0f;

        //UITextView *theTextView;
        theTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
        theTextView.scrollEnabled = NO;
        theTextView.editable = NO;

        theTextView.text = [NSString stringWithFormat:@"This is a very long text"];

           // 3
        //UIImageView *newPageView = [[UIImageView alloc] initWithImage:[self.pageImages objectAtIndex:page]];
        theTextView.contentMode = UIViewContentModeScaleAspectFit;
        theTextView.frame = frame;
        [self.scrollView addSubview:theTextView];
        // 4
        [self.pageViews replaceObjectAtIndex:page withObject:theTextView];
    }
}
4

2 回答 2

2

它们都是UIView子类。它应该以完全相同的方式工作。如果您不希望它们滚动,只需停用allowUserInteraction,并且应该以与填充相同的方式滚动。UITextViewsUIScrollViewUIImageViews

于 2013-08-21T19:11:09.727 回答
0

添加 UITextView 的方式与添加 UIImageView 的方式完全相同。初始化一个 UITextView,设置你想要的任何属性,并将它作为子视图添加到 UIScrollView。所以无论你在哪里添加 UIImageViews,用这样的代码替换那个代码:

self.theTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
self.theTextView.scrollEnabled = NO;
self.theTextView.editable = NO;
... //however else you want to modify your UITextView

[self.theScrollView addSubview:self.theTextView];
于 2013-08-21T19:12:50.867 回答