從零開始學習ios(UIImageView)控制項及其屬性

來源:互聯網
上載者:User

標籤:

 //建立圖片視圖時就設定Frame的屬性和大小

    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(60, 20, 80, 100)];

    [img setImage:[UIImage imageNamed:@"mtxx6"]];

    

  /* 建立圖片視圖的另外四種方法

   type img{

        UIImageView *img1 = [[UIImageView alloc]init];

        UIImageView *img2 = [[UIImageView ALLOC] initWithImage:(UIImage *)];

        UIImageView *img3 = [[UIImageView alloc] initWithImage:(UIImage *)];

        UIImageView *img4 = [[UIImageView alloc] initWithCoder:(NSCoder *)];

    }UIImageView

   */

     //設定Frame的屬性,可以設定其位置和大小

  //img.frame = CGRectMake(CGFloat x, CGFloat y, <#CGFloat width#>, <#CGFloat height#>)

// bounds只能設定其大小,bounds是將UIImageView控制項以原來的中心進行縮放。

//    img.bounds = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)

    //contentMode 設定圖片的顯示方式.我設定為根據視圖進行等比列縮小

    img.contentMode = UIViewContentModeScaleAspectFit;

    //UIViewContentModeScaleAspectFill 保證部分圖片比例不變,但是填充整個ImageView,可能只有部分圖片顯示出來了

    //UIViewContentModeScaleAspectFit 根據視圖的比例而將Image全部顯示與視圖中,所以視圖會部分空白

    //UIViewContentModeScaleToFill 圖片根據圖片視圖視窗的大小然後進行填充,導致圖片變形

    //UIViewContentModeRedraw  對縮放和尺寸調整過程中的視圖外觀控制

    //UIViewContentModeCenter  圖片顯示原圖大小顯示中間部分,

    //UIViewContentModeTop    圖片顯示原圖大小顯示上面部分

    //UIViewContentModeBottom 圖片顯示原圖大小顯示下面部分

    //UIViewContentModeLeft  圖片顯示原圖大小顯示左邊部分

    //UIViewContentModeRight 圖片顯示原圖大小顯示右邊部分

    //UIViewContentModeTopLeft 圖片顯示原圖大小顯示左上方部分

    //UIViewContentModeTopRight  圖片顯示原圖大小顯示右上方部分

    //UIViewContentModeBottomLeft 圖片顯示原圖大小顯示左下方部分

    //UIViewContentModeBottomRight 圖片顯示原圖大小顯示右下方部分

//    img.center = CGPointMake(40.0, 80.0);

    //center 更改UIImangeView的位置

//    img.transform = CGAffineTransformMakeRotation(60.0);

    //transfrom 圍繞ImageView的中心順時針旋轉

//    img.transform = CGAffineTransformMakeScale(8.0,2.0);

    //transform 縮放映像

    //[img.layer setBorderColor:[[UIColor redColor] CGClolor]];

    [img.layer setBorderColor:[[UIColor redColor] CGColor] ];

   //bordercolor 設定邊框顏色

    img.hidden = NO;//NO為顯示圖片,YES為隱藏圖片

    img.alpha = 0.5;//設定透明度

    img.highlightedImage = [UIImage imageNamed:@"mtxx9"];

    // [img.layer setBorderColor: [[UIColor whiteColor] CGColor]];

    //setShouldRasterize 設定柵格化,NO不柵格化,YES會柵格層中的資料

    [img.layer setShouldRasterize:NO];

    /*

     //imageArray表示一個數組

     img.animationImages = imageArray;

     //設定所有的圖片在多少秒內播放完畢

     img.animationDuration = [imageArray count];

     //不重複播放多少遍,o表示無數遍

     img.animationRepeatCount = 0;

     //開始播放

     [img startAnimating];

    */

    //將圖片尺寸調整為內容圖片相同

    [img sizeToFit];

    [self.view addSubview:img];

 

從零開始學習ios(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.