<code class="hljs avrasm has-numbering">ViewController<span class="hljs-preprocessor">.m</span> -------------------------------------------------- (void)viewDidLoad { [super viewDidLoad]<span class="hljs-comment">;</span> // Do any additional setup after loading the view, typically from a nib. //大圖片滑動 UIScrollView *scrollView = [[UIScrollView alloc] init]<span class="hljs-comment">;</span> scrollView<span class="hljs-preprocessor">.frame</span> = CGRectMake(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, self<span class="hljs-preprocessor">.view</span><span class="hljs-preprocessor">.bounds</span><span class="hljs-preprocessor">.size</span><span class="hljs-preprocessor">.width</span>, self<span class="hljs-preprocessor">.view</span><span class="hljs-preprocessor">.bounds</span><span class="hljs-preprocessor">.size</span><span class="hljs-preprocessor">.height</span>)<span class="hljs-comment">;//設置UIScrollView的可視范圍</span> scrollView<span class="hljs-preprocessor">.backgroundColor</span> = [UIColor grayColor]<span class="hljs-comment">;//設置UIScrollView背景顏色為灰色</span> [self<span class="hljs-preprocessor">.view</span> addSubview:scrollView]<span class="hljs-comment">;//加載UIScrollView</span> UIImageView *imageView = [[UIImageView alloc] init]<span class="hljs-comment">;</span> imageView<span class="hljs-preprocessor">.image</span> = [UIImage imageNamed:@<span class="hljs-string">"xingkong.jpg"</span>]<span class="hljs-comment">;</span> CGFloat imgW = imageView<span class="hljs-preprocessor">.image</span><span class="hljs-preprocessor">.size</span><span class="hljs-preprocessor">.width</span><span class="hljs-comment">;//圖片的寬度</span> CGFloat imgH = imageView<span class="hljs-preprocessor">.image</span><span class="hljs-preprocessor">.size</span><span class="hljs-preprocessor">.height</span><span class="hljs-comment">;//圖片的高度</span> imageView<span class="hljs-preprocessor">.frame</span> = CGRectMake(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, imgW, imgH)<span class="hljs-comment">;</span> [scrollView addSubview:imageView]<span class="hljs-comment">;</span> //設置UIScrollView的滾動范圍(內容大小) scrollView<span class="hljs-preprocessor">.contentSize</span> = imageView<span class="hljs-preprocessor">.image</span><span class="hljs-preprocessor">.size</span><span class="hljs-comment">;</span> }-</code>