zoukankan      html  css  js  c++  java
  • UI: UIImageView

    以图片的实际宽和高显示在屏幕上。 
    UIImage *macBookAir = [UIImage imageNamed:@"MacBookAir.png"]; 
    //initWithImage:
    self.myImageView = [[UIImageView alloc] initWithImage:macBookAir];

    给定大小initWithFrame :

    self.myImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    我们设定了这个图片的 frame,但是这个图片显示在 image view 中有时是不准确的(拉长等等)。
    我们可以通过设置图片视图的 contentMode 属性来改善这个问题。这个属性属于 UIContentMode 类型。如下所示。 
    typedef enum { 
    UIViewContentModeScaleToFill, 
    UIViewContentModeScaleAspectFit,
    UIViewContentModeScaleAspectFill, 
    UIViewContentModeRedraw, 
    UIViewContentModeCenter, 
    UIViewContentModeTop, 
    UIViewContentModeBottom, 
    UIViewContentModeLeft, 
    UIViewContentModeRight,
    UIViewContentModeTopLeft, 
    UIViewContentModeTopRight, 
    UIViewContentModeBottomLeft, 
    UIViewContentModeBottomRight,
    } UIViewContentMode;
    下面对 UIViewContentMode 中最有用的几个值进行解释:
    UIViewContentModeScaleToFill

    这个值会将 image view 里的图片进行缩放,以充满整个 image view。 

    UIViewContentModeScaleAspectFit

    这个值会确保 image view 里的图片有正确的长宽比,并且会确保图片适应 image view 的边界。

    UIViewContentModeScaleAspectFill

    这个值会确保 image view 里的图片有正确的长宽比,并且使图片充满整个图片视图的 边界。为了能使这个值正常工作,确保将 clipsToBounds 这个属性值设置为 YES。 

    self.myImageView.contentMode = UIViewContentModeScaleAspectFit;
  • 相关阅读:
    URL重定向功能与APS.NET的固化功能结合
    How can I share types when generate WebSevice proxies using local paths
    C# Coding Standard Naming Conventions and Style
    VS自动化对象模型
    odac 如何捕捉错误odac 如何捕捉错误
    webbrower应用实例
    webbrower在同一个窗口打开新增窗口
    [DELPHI]$2501錯誤處理
    暴力破解例子
    webbrower连接在新form中显示
  • 原文地址:https://www.cnblogs.com/safiri/p/4023742.html
Copyright © 2011-2022 走看看