【问题标题】:Image slider pages printing issue?图像滑块页面打印问题?
【发布时间】:2014-12-17 16:32:25
【问题描述】:

我正在尝试创建图像滑块视图以将 3 张图片作为滑块查看。但每次它只创建一张带有 3 张幻灯片的图片。那么请问我的问题在哪里?

是否应该在每页幻灯片中打印一张图片?

- (void)imageCreater{

self.view.backgroundColor = [UIColor whiteColor];
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

CGRect svrect_ = CGRectZero;
svrect_.size.height = self.view.bounds.size.height/3*2;
svrect_.size.width = self.view.bounds.size.width/3*2;
CGPoint svcenter_ = CGPointZero;
svcenter_.x = self.view.center.x;
svcenter_.y = self.view.center.y+45;
CGSize svconsize = CGSizeZero;
svconsize.height = svrect_.size.height;
svconsize.width = svrect_.size.width * 3;

CGPoint pgconcenter_ = CGPointZero;
pgconcenter_.x = self.view.center.x;
pgconcenter_.y = svcenter_.y + (svrect_.size.height/2) + 20;

CGRect btnrect_ = CGRectZero;
btnrect_.size.width = 250;
btnrect_.size.height = 50;
CGPoint btncenter_ = CGPointZero;
btncenter_.x = self.view.center.x;
btncenter_.y = self.view.bounds.size.height-65;

_backgroundimageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:_backgroundimageview];

_scrollview = [[UIScrollView alloc] initWithFrame:svrect_];
_scrollview.center = svcenter_;
_scrollview.backgroundColor = [UIColor whiteColor];
_scrollview.contentSize = svconsize;
_scrollview.pagingEnabled = true;
_scrollview.bounces = false;
_scrollview.delegate = self;
_scrollview.showsHorizontalScrollIndicator = false;
_scrollview.layer.cornerRadius = 2;
[self.view addSubview:_scrollview];

_pgcontrol = [[UIPageControl alloc] initWithFrame:CGRectZero];
_pgcontrol.pageIndicatorTintColor = [UIColor colorWithWhite:0.8 alpha:1];
_pgcontrol.currentPageIndicatorTintColor = [UIColor colorWithWhite:0.6 alpha:1];
_pgcontrol.numberOfPages = 3;
_pgcontrol.currentPage = 0;
[_pgcontrol sizeToFit];
_pgcontrol.center = pgconcenter_;
[self.view addSubview:_pgcontrol];

UIImageView*iv_ = [[UIImageView alloc] initWithFrame:svrect_];
iv_.contentMode = UIViewContentModeScaleAspectFit;
iv_.clipsToBounds = true;
iv_.image = [UIImage imageNamed:@"31902.png"];

UIImageView*iv1_ = [[UIImageView alloc] initWithFrame:svrect_];
iv1_.contentMode = UIViewContentModeScaleAspectFit;
iv1_.clipsToBounds = true;
iv1_.image = [UIImage imageNamed:@"31901.png"];

UIImageView*iv2_ = [[UIImageView alloc] initWithFrame:svrect_];
iv2_.contentMode = UIViewContentModeScaleAspectFit;
iv2_.clipsToBounds = true;
iv2_.image = [UIImage imageNamed:@"31900.png"];

[_scrollview addSubview:iv_];
[_scrollview addSubview:iv1_];
[_scrollview addSubview:iv2_];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

int page_ = (int)round(scrollView.contentOffset.x / scrollView.frame.size.width);
if (page_== inter-1) {
    [_button setTitle:startText forState:UIControlStateNormal];
}else{
    [_button setTitle:nextText forState:UIControlStateNormal];
}
_pgcontrol.currentPage = page_;
}

【问题讨论】:

    标签: ios objective-c uiscrollview uipagecontrol


    【解决方案1】:

    您正在为三个 imageView 设置相同的框架 如下改变框架,你会在slideView中得到三张图片

    UIImageView*iv_ = [[UIImageView alloc] initWithFrame:svrect_];
    iv_.contentMode = UIViewContentModeScaleAspectFit;
    iv_.clipsToBounds = true;
    iv_.image = [UIImage imageNamed:@"images-1.jpg"];
    
    svrect_.origin.x += iv_.frame.size.width;
    
    UIImageView*iv1_ = [[UIImageView alloc] initWithFrame:svrect_];
    iv1_.contentMode = UIViewContentModeScaleAspectFit;
    iv1_.clipsToBounds = true;
    iv1_.image = [UIImage imageNamed:@"images-2.jpg"];
    
    svrect_.origin.x += iv1_.frame.size.width;
    
    UIImageView*iv2_ = [[UIImageView alloc] initWithFrame:svrect_];
    iv2_.contentMode = UIViewContentModeScaleAspectFit;
    iv2_.clipsToBounds = true;
    iv2_.image = [UIImage imageNamed:@"images-3.jpg"];
    
    [_scrollview addSubview:iv_];
    [_scrollview addSubview:iv1_];
    [_scrollview addSubview:iv2_];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2016-10-14
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多