學習iOS控件之UIImageView

  學習iOS控件之UIImageView

UIIamgeView是用來顯示圖片的,需要一個UIImage來裝在圖片,在UIImageView上顯示,和UIButton之間的區別在於,默認情況下是不能點擊的,不接受用戶行爲。UIImageView還可以用來播放序列圖。

UIImageView的官網地址:https://developer.apple.com/reference/uikit/uiimageview 點擊打開鏈接


    //控件初始化
    UIImageView *imageView = [[UIImageView alloc] init];
    
    //設置背景顏色
    imageView.backgroundColor = [UIColor redColor];
    
    //設置frame
    imageView.frame = CGRectMake(50, 50, 200, 246);
    
    //設置圓角
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 20;
    
    //設置邊框顏色和大小
    imageView.layer.borderColor = [UIColor orangeColor].CGColor;
    imageView.layer.borderWidth = 2;
    
    //UIImage
    UIImage *image = [UIImage imageNamed:@"child"];
    imageView.image = image;
    
    //UIImageView默認不接受用戶行爲,YES打開用戶行爲
    imageView.userInteractionEnabled = YES;
    
    //設置中心點
    imageView.center = CGPointMake(200, 200);
    
    //添加手勢
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
    [imageView addGestureRecognizer:singleTap];
    
    [self.view addSubview:imageView];
    
    
   
    //播放一系列圖片
    UIImage *image1 = [UIImage imageNamed:@"one"];
    UIImage *image2 = [UIImage imageNamed:@"two"];
    UIImage *image3 = [UIImage imageNamed:@"three"];
    NSArray *imagesArray = @[image1,image2,image3];
    imageView.animationImages = imagesArray;
    
    //序列圖播放時間
    imageView.animationDuration = 2;
    
    //播放多少遍,0表示無數遍
    imageView.animationRepeatCount = 0;
    
    // 開始播放
    [imageView startAnimating];


發佈了29 篇原創文章 · 獲贊 6 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章