UIImageView的使用

来源:互联网 发布:mac mini忘记开机密码 编辑:程序博客网 时间:2024/06/03 16:44

//创建imageView

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

    imgView.backgroundColor = [UIColorredColor];

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

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

    imgView.image = image;

    

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

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

//    imgView.highlighted = YES;

    

    //边框加工

    imgView.layer.borderWidth =1;

    imgView.layer.borderColor = [UIColorgreenColor].CGColor;

    imgView.layer.cornerRadius =5;

    

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

    imgView.contentMode =UIViewContentModeScaleAspectFit;

    

    [_window addSubview:imgView];

    

    

//    imgView.animationImages =

    

    NSMutableArray *imgArray = [[NSMutableArrayalloc] init];

    

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

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

        UIImage *img = [UIImageimageNamed:imgName];

        

        //设置UIImage的图片拉伸点

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

        

        [imgArray addObject:img];

    }

    

    //设置imgView的动画集合

    imgView.animationImages = imgArray;

    //设置动画的时间

    imgView.animationDuration =5;

    

    //开始动画

    [imgView startAnimating];

    

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeContactAdd];

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

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

    [imgView addSubview:button];

    

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

    imgView.userInteractionEnabled =YES;

    

    

    

    

    

    

    return YES;

}


- (void)buttonAction {


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

}


0 0
原创粉丝点击