UI_UIImageView 基本操作,ui_uiimageview

來源:互聯網
上載者:User

UI_UIImageView 基本操作,ui_uiimageview
UI_UIImageView 常用方法

// 使用ImageView 通過 name 找到圖片    UIImage *image = [UIImage imageNamed:@"bg_2"];    // 添加 image 到 imageView 上    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];    // 設定圖片位置和大小    imageView.frame = CGRectMake(40, 40, 90, 160);    imageView.backgroundColor = [UIColor redColor];    // 設定透明度    imageView.alpha = 0.5;    // 為圖片添加點擊事件    // userInteractionEnabled 為 YES ,才能響應點擊事件    imageView.userInteractionEnabled = YES; // 設定圖片可以互動    // 設定手勢    UITapGestureRecognizer *singleTag = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];    // 添加手勢    [imageView addGestureRecognizer:singleTag];    // 顯示/隱藏  YES 為隱藏    imageView.hidden = NO;    // 擷取網路中的圖片    UIImage *netImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.google.com"]]];    // 將 image 添加到 window 上,並釋放記憶體    [self.window addSubview:imageView];    [imageView release];    imageView = nil; // 安全釋放
動態圖
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.tiff"]];    imageView.frame = CGRectMake(40, 50, 100, 100);    // 把一組圖片加到 imageView 上面    NSMutableArray *array = [NSMutableArray array];    for (int i = 1; i < 5; i++) {//        NSString *name = [NSString stringWithFormat:@"00%d.tiff", i];//        UIImage *image = [UIImage imageNamed:name];        // 上面兩句可以合為一句        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff", i]];        [array addObject:image];    }    // 把數組放到imageView中    imageView.animationImages = array;    [self addSubview:imageView];    // 播放時間    imageView.animationDuration = 0.4f;    // 播放次數    imageView.animationRepeatCount = 0; // 0 就是無限次    // 開始動畫    [imageView startAnimating];    // 結束動畫】//    [imageView stopAnimating];

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

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