UIImageView的使用

//创建imageView

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 280)];

    imgView.backgroundColor = [UIColor redColor];

    //设置显示的图片,默认后缀名是png

    UIImage *image = [UIImage imageNamed:@"1"];

    imgView.image = image;

    

    //设置高亮状态下显示的图片

    imgView.highlightedImage = [UIImage imageNamed:@"scene1.jpg"];

//    imgView.highlighted = YES;

    

    //边框加工

    imgView.layer.borderWidth = 1;

    imgView.layer.borderColor = [UIColor greenColor].CGColor;

    imgView.layer.cornerRadius = 5;

    

    //设置图片的填充模式UIViewContentModeScaleAspectFit:图片等比例拉伸

    imgView.contentMode = UIViewContentModeScaleAspectFit;

    

    [_window addSubview:imgView];

    

    

//    imgView.animationImages =

    

    NSMutableArray *imgArray = [[NSMutableArray alloc] init];

    

    for (int i=1; i<22; i++) {

        NSString *imgName = [NSString stringWithFormat:@"%d.jpg",i];

        UIImage *img = [UIImage imageNamed:imgName];

        

        //设置UIImage的图片拉伸点

        //img resizableImageWithCapInsets:UIEdgeInsetsMake(距上, 距左, 距下, 距右);

        

        [imgArray addObject:img];

    }

    

    //设置imgView的动画集合

    imgView.animationImages = imgArray;

    //设置动画的时间

    imgView.animationDuration = 5;

    

    //开始动画

    [imgView startAnimating];

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];

    button.frame = CGRectMake(20, 20, 20, 20);

    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];

    [imgView addSubview:button];

    

    //注意,在UIImageView添加点击事件时一定要改为yes

    imgView.userInteractionEnabled = YES;

    

    

    

    

    

    

    return YES;

}


- (void)buttonAction {


    NSLog(@"按钮被点击了");

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值