<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      iOS開發(fā)-圖片UIImage

      UIImageUIImageView 是 iOS 開發(fā)中常用的兩個類,分別用于表示圖像數(shù)據(jù)和顯示圖像。

      UIImage

      UIImage 是一個表示圖像數(shù)據(jù)的類,可以從文件、數(shù)據(jù)、圖像資源庫等加載圖像。UIImage 支持多種圖像格式,包括 PNG、JPEG、GIF 等。

      創(chuàng)建 UIImage

      1. 從文件創(chuàng)建

        UIImage *image = [UIImage imageNamed:@"exampleImage"];
        
      2. 從數(shù)據(jù)創(chuàng)建

        NSData *imageData = [NSData dataWithContentsOfFile:@"path/to/image"];
        UIImage *image = [UIImage imageWithData:imageData];
        
      3. 從 URL 創(chuàng)建

        NSURL *imageUrl = [NSURL URLWithString:@"https://example.com/image.png"];
        NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
        UIImage *image = [UIImage imageWithData:imageData];
        
      4. 從顏色創(chuàng)建

        UIColor *color = [UIColor redColor];
        CGSize size = CGSizeMake(100, 100);
        UIGraphicsBeginImageContext(size);
        [color setFill];
        UIRectFill(CGRectMake(0, 0, size.width, size.height));
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        

      處理 UIImage

      • 獲取圖像尺寸

        CGSize imageSize = image.size;
        
      • 獲取圖像的縮放比例

        CGFloat scale = image.scale;
        
      • 保存圖像到文件

        NSData *imageData = UIImagePNGRepresentation(image);
        [imageData writeToFile:@"path/to/save.png" atomically:YES];
        

      UIImageView

      UIImageView 是一個用于顯示圖像的視圖類。它可以顯示 UIImage 對象,并提供了一些方便的方法來調(diào)整圖像的顯示方式。

      • 創(chuàng)建 UIImageView

        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(50, 50, 100, 100);
        

      配置 UIImageView

      • 設(shè)置圖像

        imageView.image = image;
        
      • 內(nèi)容模式

        UIImageView 提供了多種內(nèi)容模式,用于控制圖像如何在視圖中顯示:

        imageView.contentMode = UIViewContentModeScaleAspectFit;  // 保持比例適應(yīng)視圖
        imageView.contentMode = UIViewContentModeScaleAspectFill; // 保持比例填充視圖,可能會裁剪圖像
        imageView.contentMode = UIViewContentModeCenter;          // 居中顯示圖像
        
      • 設(shè)置邊框和圓角

        imageView.layer.borderColor = [UIColor blackColor].CGColor;
        imageView.layer.borderWidth = 2.0;
        imageView.layer.cornerRadius = 10.0;
        imageView.clipsToBounds = YES;
        

      動畫 UIImageView

      • 逐幀動畫

        UIImageView 可以通過設(shè)置 animationImages 屬性來播放逐幀動畫:

        imageView.animationImages = @[image1, image2, image3];
        imageView.animationDuration = 1.0;  // 動畫時長
        imageView.animationRepeatCount = 0; // 無限循環(huán)
        [imageView startAnimating];
        

      使用示例

      以下是一個完整的示例,展示了如何使用 UIImageUIImageView

      ViewController.h

      #import <UIKit/UIKit.h>
      
      @interface ViewController : UIViewController
      
      @end
      

      ViewController.m

      #import "ViewController.h"
      
      @implementation ViewController
      
      - (void)viewDidLoad {
          [super viewDidLoad];
          self.view.backgroundColor = [UIColor whiteColor];
          
          // 創(chuàng)建 UIImage 對象
          UIImage *image = [UIImage imageNamed:@"exampleImage"];
          
          // 創(chuàng)建 UIImageView 對象并設(shè)置圖像
          UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
          imageView.frame = CGRectMake(50, 50, 200, 200);
          imageView.contentMode = UIViewContentModeScaleAspectFit;
          imageView.layer.borderColor = [UIColor blackColor].CGColor;
          imageView.layer.borderWidth = 2.0;
          imageView.layer.cornerRadius = 10.0;
          imageView.clipsToBounds = YES;
          [self.view addSubview:imageView];
          
          // 動畫 UIImageView
          UIImage *image1 = [UIImage imageNamed:@"frame1"];
          UIImage *image2 = [UIImage imageNamed:@"frame2"];
          UIImage *image3 = [UIImage imageNamed:@"frame3"];
          UIImageView *animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 300, 200, 200)];
          animatedImageView.animationImages = @[image1, image2, image3];
          animatedImageView.animationDuration = 1.0;
          animatedImageView.animationRepeatCount = 0;
          [animatedImageView startAnimating];
          [self.view addSubview:animatedImageView];
      }
      
      @end
      
      posted @ 2024-07-06 20:17  機(jī)械心  閱讀(149)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 无码一级视频在线| 海门市| 久久国内精品一国内精品| 竹山县| 日韩V欧美V中文在线| 麻豆国产AV剧情偷闻女邻居内裤| 在线中文字幕国产一区| 色国产视频| 国产成人亚洲欧美二区综合| 欧美搡bbbbb搡bbbbb| 人人人澡人人肉久久精品| 中文字幕在线无码一区二区三区 | 国产女人高潮视频在线观看| 岛国一区二区三区高清视频| 亚洲精品国产自在久久| 国产免费高清69式视频在线观看 | 最新精品国偷自产在线| 国产揄拍国产精品| 久久久无码一区二区三区| 热久久这里只有精品99| 日韩国产精品中文字幕| 亚洲av无码成人精品区一区| 亚洲香蕉伊综合在人在线| 亚洲区福利视频免费看| 又大又粗欧美成人网站| 久久国产成人精品av| 国产av一区二区三区精品| 中文字幕国产日韩精品| 国产丝袜在线精品丝袜不卡| 亚洲熟妇熟女久久精品综合| 人人妻人人狠人人爽| 免费看黄色亚洲一区久久| 国产国产午夜福利视频| 99久久亚洲综合精品成人网| 亚洲sm另类一区二区三区| 国产裸体美女视频全黄| 亚洲色在线v中文字幕| 亚欧成人精品一区二区乱| 亚洲色婷婷久久精品av蜜桃久久| 欧美福利在线| 少妇高潮太爽了在线视频|