ios-UI控件精讲之【6】-UIImageView

原文:http://www.jianshu.com/p/3eaa34649b79


UIImageView属性
  • 创建UIImageView对象
    UIImageView *imageView = [[UIImageView alloc] init];
  • 设置frame-->位置和尺寸
    imageView.frame = CGRectMake(100, 100, 175, 175);
  • 创建时设置frame
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 267, 400)];
  • 根据图片的大小,设置frame
imageView.frame = CGRectMake(100, 100, image.size.width, image.size.height);
  • 设置背景颜色
    imageView.backgroundColor = [UIColor yellowColor];
  • 设置显示的图片
常用创建UIImage的方法:
     1.imageName: 后面传入图片的名字
     2.imageWithContentOfFile: 图片的全路径
     */
    UIImage *image = [UIImage imageNamed:@"1"];
  • 将image对象设置imageView的属性
    imageView.image = image;

帧动画

  • 加载所有图片
NSMutableArray *images = [NSMutableArray array];
    for (int i = 0; i < 20; i++) {
        NSString *imageName = [NSString stringWithFormat:@"%d", i + 1];
        UIImage *image = [UIImage imageNamed:imageName];

        [images addObject:image];
  • 给imageView设置图片
self.imageView.animationImages = images;
  • 动画执行次数
self.imageView.animationRepeatCount = 2;
默认是0,无限循环
  • 动画执行时间
self.imageView.animationDuration = 1;
  • 开始动画
[self.imageView startAnimating];
  • 停止动画
 [self.imageView stopAnimating];
//清空数组里的图片
self.standImages = nil;
 self.imageView.animationImages = nil;
  • 过一个时间执行另外一个动作
[self performSelector:@selector(stand) withObject:nil afterDelay:zhaoTime];

播放声音
  • 根据音频文件名加载资源
    NSURL *url = [[NSBundle mainBundle] URLForResource:soundName withExtension:@"mp3"];
  • 创建AVPlayerItem的对象
    AVPlayerItem *Item = [[AVPlayerItem alloc] initWithURL:url];
  • 创建AVPlayer对象
AVPlayer * player = [[AVPlayer alloc]initWithPlayerItem:Item];
  • 播放声音
    [self.player play];
  • 改变声音播放速率
    self.player.rate = 1.5;
  • 另一个Item
AVPlayerItem *item2 = [[AVPlayerItem alloc] initWithURL:url];
  • 替换前一个Item
[self.player replaceCurrentItemWithPlayerItem:item2];
  • 播放声音
    [self.player play];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值