gpt4 book ai didi

iphone - 如何用水平 ScrollView 显示 View 中的内容?

转载 作者:行者123 更新时间:2023-12-03 21:18:38 25 4
gpt4 key购买 nike

我正在制作一个应用程序,其中我正在实现如下事件:在 View 底部有一个沿水平方向滚动的 ScrollView 。在 ScrollView 中,我添加了一些文本字段和图像。它看起来就像新闻 channel 在屏幕底部显示突发新闻并更新它,然后单击时显示详细信息屏幕。我也想在应用程序中做,所以我该怎么做?

我要做什么才能在应用程序中获得此类功能?如何使用 ScrollView 以便我在 View 中显示一些文本,然后单击该文本然后获取详细 View ?

最佳答案

您可以将所有图像加载到数组中。您可以设计一个具有一个 ImageView 和一些文本字段的 View ,并尝试以下代码:

数组名称:examplearray 和 View 名称:exampleview

-(void)updateImagesInScrollView
{
int cnt = [examplearray count];

for(int j=0; j< cnt; ++j)
{
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"exampleview"
owner:self
options:nil];

UIView *myView = [nibContents objectAtIndex:0];
exampleview * rview= (exampleview *)myView;
/* you can get your image from the array and set the image*/
rview.imageview.image = yourimage;
/*adding the view to your scrollview*/
[self.ScrollView addSubview:rview];
}
/* you need to set the content size of the scroll view */
self.ScrollView.contentSize = CGSizeMake(X, self.mHorizontalScrollView.contentSize.height);
}

上面的代码是在水平 ScrollView 中显示图像和文本字段。我建议您在该 View 上有一个自定义按钮,并且在该按钮操作中您可以编写代码来获取详细信息屏幕。

关于iphone - 如何用水平 ScrollView 显示 View 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7390782/

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