iOS-UI控制項之UIImageView

來源:互聯網
上載者:User

標籤:

contentMode屬性
  • 帶有scale單詞的:圖片有可能會展開

    • UIViewContentModeScaleToFill
      • 將圖片展開至填充整個imageView
      • 圖片顯示的尺寸跟imageView的尺寸是一樣的
    • 帶有aspect單詞的:保持圖片原來的寬高比
      • UIViewContentModeScaleAspectFit
        • 保證剛好能看到圖片的全部
      • UIViewContentModeScaleAspectFill
        • 展開至圖片的寬度或者高度跟imageView一樣
  • 沒有scale單詞的:圖片絕對不會被展開,保持圖片的原尺寸

    • UIViewContentModeCenter
    • UIViewContentModeTop
    • UIViewContentModeBottom
    • UIViewContentModeLeft
    • UIViewContentModeRight
    • UIViewContentModeTopLeft
    • UIViewContentModeTopRight
    • UIViewContentModeBottomLeft
    • UIViewContentModeBottomRight
小文法點
  • 不能直接修改:OC對象的結構體屬性的成員
  • 下面的寫法是錯誤的
imageView.frame.size = imageView.image.size;
  • 正確寫法
CGRect tempFrame = imageView.frame;tempFrame.size = imageView.image.size;imageView.frame = tempFrame;
initWithImage:方法
  • 利用這個方法建立出來的imageView的尺寸和傳入的圖片尺寸一樣
修改frame的3種方式
  • 直接使用CGRectMake函數
imageView.frame = CGRectMake(100, 100, 200, 200);
  • 利用臨時結構體變數
CGRect tempFrame = imageView.frame;tempFrame.origin.x = 100;tempFrame.origin.y = 100;tempFrame.size.width = 200;tempFrame.size.height = 200;imageView.frame = tempFrame;
  • 使用大括弧{}形式
imageView.frame = (CGRect){{100, 100}, {200, 200}};
  • 抽取重複代碼

    • 將相同代碼放到一個新的方法中
    • 不用的東西就變成方法的參數
  • 圖片的載入方式

    • 有緩衝
      UIImage *image = [UIImage imageNamed:@"圖片名"];
      • 使用場合:圖片比較小、使用頻率較高
      • 建議把需要緩衝的圖片直接放到Images.xcassets
    • 無緩衝
      NSString *file = [[NSBundle mainBundle] pathForResource:@"圖片名" ofType:@"圖片的副檔名"];UIImage *image = [UIImage imageWithContentsOfFile:@"圖片檔案的全路徑"];
      • 使用場合:圖片比較大、使用頻率較小
      • 不需要緩衝的圖片不能放在Images.xcassets
      • 當放在Supporting Files中,匯入時選擇Create folder references時候,負載檔案需要匯入檔案名稱‘/images/imag_01’
    • 放在Images.xcassets裡面的圖片,只能通過圖片名去載入圖片
  • 延遲做一些事情

[abc performSelector:@selector(stand:) withObject:@"123" afterDelay:10];// 10s後自動調用abc的stand:方法,並且傳遞@"123"參數
  • 音頻檔案的簡單播放
// 建立一個音頻檔案的URL(URL就是檔案路徑對象)NSURL *url = [[NSBundle mainBundle] URLForResource:@"音頻檔案名稱" withExtension:@"音頻檔案的副檔名"];// 建立播放器self.player = [AVPlayer playerWithURL:url];// 播放[self.player play];

iOS-UI控制項之UIImageView

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.