你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> IOS大圖片處理

IOS大圖片處理

編輯:關於IOS
  • 大圖片處理
<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>
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved