ios scrollview淺談(入門)

來源:互聯網
上載者:User

標籤:ios   ios開發   uiscrollview   uiimageview   編程   

今天小小激勵了下,感謝各位以及csdn的朋友們的支援。我會給大家帶來更好的文章,今天最後一篇關於scrollview來做個入門介紹,相信很多朋友已經迫不及待了,哈哈。下面我們進入主題。

建立一個工程:

#import "ViewController.h"


@interface ViewController ()


{

    //存scrollview

    UIScrollView *_sv;

}

@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

 

    // 先加在scrollview然後在載入imageview

    //imageview在scrollview上面

      [selfcresteScrollView];

      [selfcreateImageView];

  

    

    

    

}


//建立滾動視圖

-(void)cresteScrollView

{

    UIScrollView *sv = [[UIScrollViewalloc]init];

    //設定滾動視圖顯示地區(只是劃定該地區為scrollview不要和)

    sv.frame =CGRectMake(30,50, 300,500);

    sv.backgroundColor = [UIColorcyanColor];

    

    //設定滾動視圖內容大小(內容大小直接決定你視圖的顯示大小)

    sv.contentSize =CGSizeMake(300,500);

    //增加額外顯示地區

    sv.contentInset =UIEdgeInsetsMake(20,40, 60,80);

    

    

    //開啟彈動效果

    sv.bounces =YES;

    

    //設定滾動指示條是否顯示

    //水平方向

    sv.showsHorizontalScrollIndicator =YES;

    //垂直方向

    sv.showsVerticalScrollIndicator =YES;

    [self.viewaddSubview:sv];

    

    _sv = sv;

}

//建立imageview

-(void)createImageView

{

    UIImageView *imageView = [[UIImageViewalloc]init];

    

    imageView.frame =_sv.bounds;

    

    imageView.image = [UIImageimageNamed:@"02.jpg"];

    

    [_svaddSubview:imageView];

    

}

@end


這張圖片是我手工畫的,很有趣吧?明天就過年了,就不更新了。要和家人團聚,打掃衛生,準備菜肴。祝大家過個好年,來年一定更加好,哈哈。


ios scrollview淺談(入門)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.