我正在尝试为我的应用程序创建一个欢迎页面(带有屏幕截图)。
我已经提取了一些示例,并将其制作为文本滚动条。我已经尝试了数周,但没有成功。谢谢

int numberOfPages = 5;
UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
someScrollView.pagingEnabled = YES;
someScrollView.contentSize = CGSizeMake(numberOfPages * someScrollView.frame.size.width, someScrollView.frame.size.height);
[self.view addSubview:someScrollView];

for (int i = 0; i < numberOfPages; i++) {
    UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * someScrollView.frame.size.width + 20,
                                                                  20,
                                                                  someScrollView.frame.size.width - 40,
                                                                  20)];
    tmpLabel.textAlignment = UITextAlignmentCenter;
    tmpLabel.text = [NSString stringWithFormat:@"THIS ACTUALLY WORKS!! %d", i];
    [someScrollView addSubview:tmpLabel];
}
这是我对图像进行的失败尝试:
int numberOfPages = 5;
UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
someScrollView.pagingEnabled = YES;
someScrollView.contentSize = CGSizeMake(numberOfPages * someScrollView.frame.size.width, someScrollView.frame.size.height);
[self.view addSubview:someScrollView];

for (int i = 0; i < numberOfPages; i++) {
    UIImageView *tmpLabel = [[UIImageView alloc] initWithFrame:CGRectMake(i * someScrollView.frame.size.width + 20,
                                                                  20,
                                                                  someScrollView.frame.size.width - 40,
                                                                  20)];
    tmpLabel.imageAlignment = UIImageAlignmentCenter;
    tmpLabel.text = [NSString stringWithFormat:@"THIS ACTUALLY WORKS!! %d", i];
    [someScrollView addSubview:tmpLabel];
}
    UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:subview1.frame];

    if (i == 0) {
        imageView1.image = [UIImage imageNamed:@"openingScreen1.png"];
    }else if (i == 1){
        imageView1.image = [UIImage imageNamed:@"openingScreen2.png"];
    }else if (i == 2){
        imageView1.image = [UIImage imageNamed:@"openingScreen3.png"];
    }else {
        imageView1.image = [UIImage imageNamed:@"openingScreen4.png"];
    }
除非上面的图片位于上方,否则我还可能需要删除“解析”一词?我找不到这个词。
ios - 图像的ScrollView objective-c (iOS)-LMLPHP

最佳答案

尝试这个

UIScrollView *someScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,
                                                                              self.view.frame.size.width,
                                                                              self.view.frame.size.height)];
someScrollView.pagingEnabled = YES;
[someScrollView setAlwaysBounceVertical:NO];

//setup internal views
NSInteger numberOfPages = 5;


for (int i = 0; i < numberOfPages; i++)
{
     CGFloat xOrigin = i * self.view.frame.size.width+10;
    UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOrigin,70,self.view.frame.size.width,25)];
    tmpLabel.textAlignment = NSTextAlignmentCenter;
    tmpLabel.text = [NSString stringWithFormat:@"THIS ACTUALLY WORKS!! %d", i+1];
    [someScrollView addSubview:tmpLabel];



    // calculate the width


    UIImageView *image = [[UIImageView alloc] initWithFrame:
                          CGRectMake(xOrigin, tmpLabel.frame.size.height + tmpLabel.frame.origin.y + 10,
                                     self.view.frame.size.width,
                                     self.view.frame.size.height)]; // customize your width, height and y co ordinates

    image.image = [UIImage imageNamed:[NSString stringWithFormat:
                                       @"openingScreen%d.jpg", i+1]];
    image.contentMode = UIViewContentModeScaleAspectFit;
    [someScrollView addSubview:image];


}
//set the scroll view content size
someScrollView.backgroundColor = [UIColor blueColor];
someScrollView.contentSize = CGSizeMake(self.view.frame.size.width *
                                        numberOfPages,
                                        self.view.frame.size.height);
//add the scrollview to this view
[self.view addSubview:someScrollView];

样本输出是

ios - 图像的ScrollView objective-c (iOS)-LMLPHP

这里我也附了sample Project,请使用这个

关于ios - 图像的ScrollView objective-c (iOS),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32883548/

10-14 16:43
查看更多