UIScrollView、UIPageControl總結

今天學習了UIScrollView在UIScroll中有contentSize方法,contentSize在 UIScrollView裏面的尺寸, frame.size在 UIImageView控件的尺寸。對於代碼實現UIScroll要注意實例化UIScroll後,須要設置控件尺寸。即: 學習

_scrollView=[[UIScrollViewalloc]initWithFrame:CGRectMake(32.5100300,300)];這句等號前是一個在接口文件裏的屬性定義,@property(nonatomic,strong)UIScrollViewalloc *scrollView;atom


UIScrollView自己不能滾動,至關一個容器,滾動的是圖片。因此須要以實例化方式一樣步驟生成一個承載圖的UIImageView。即:
spa

  _imageView=[[UIImageViewalloc]initWithFrame:CGRectMake(i*3000300,300)];
.net

給圖片控件一個圖片:代理

    NSString *str=[NSStringstringWithFormat:@"%i.jpg",i+1];orm

    


        _imageView.image=[UIImageimageNamed:str];blog

最後給滾動控件加上圖片控件接口

       [_scrollView addSubview:_imageView];圖片

此時,要給滾動文件加尺寸:get

 _scrollView.contentSize=CGSizeMake(,,,);

最後給頁面加上滾動控件:

    [self.viewaddSubview:_scrollView];

滾動控件是否能夠翻頁的方法:  _scrollView.pagingEnabled = YES;這個不是必要實現的

UIScrollView是有代理協議的<UIScrollViewDelegate>遵照這個協議

  _scrollView.delegate=self;

必要實現方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

       return_imageView;//返回View

}


其餘方法:

    //從那個座標開始:    _ScrollView.contentOffset=CGPointMake(200, 200);

   //向哪裏移動,哪裏空出多少,座標設置上-左-下-右

   _ScrollView.contentInset=UIEdgeInsetsMake(0, 100, 100, 100);

      //是否顯示水平尺度,即下方的橫向滾動條

   _ScrollView.showsHorizontalScrollIndicator=NO;

     //是否顯示垂直尺度,即下方的縱向滾動條

   _ScrollView.showsVerticalScrollIndicator=NO;

    //代碼塊封裝自動滾動

    [UIViewanimateWithDuration:1.0fanimations:^{

        _scrollView.contentOffset=CGPointMake(100, 300);

    }];

// 開始拖拽的時候調用

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

//結束時

 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate


對於UIPageView

//實例化要設置大小

    _PageControl=[[UIPageControlalloc]initWithFrame:CGRectMake(32.5, 330, 300, 100)];

//設置開始和當前頁 

   _PageControl.currentPage=0;

    _PageControl.numberOfPages=8;

//設置顏色默認白色不會顯示出來

    _PageControl.currentPageIndicatorTintColor=[UIColorblueColor];//當前頁

    _PageControl.pageIndicatorTintColor=[UIColorblackColor];//未選頁

  //入頁面,並前置控件

    [self.viewaddSubview:_PageControl];

    [self.viewaddSubview:_scrollView];

    [self.viewbringSubviewToFront:_PageControl];

 

   練習:http://my.oschina.net/jlong/blog/472713

相關文章
相關標籤/搜索