gpt4 book ai didi

ios - UIScrollview 分页中的 UITextview

转载 作者:行者123 更新时间:2023-11-29 10:56:06 25 4
gpt4 key购买 nike

我一直在关注 tutorial用于在 UIScrollview 中对图像进行分页。

UIScrollview部分的分页。

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

不确定如何实现 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];
}
}

最佳答案

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

关于ios - UIScrollview 分页中的 UITextview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18365596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com