1

C gurus! I need your help! I have the following block of code that I used to modify an image to make it Oval shaped with a colored border. It works perfect. Now, I have 13 other images to make and don't want to have to type this out for each one. I am sure it would be much easier to store them into an array and pass into a function, but I am tripping up on how exactly to that.

CALayer *A = [img1 layer];
[A setMasksToBounds:YES];
[A setCornerRadius:31.0];
[A setBorderWidth:2.5];
[A setBorderColor:[[UIColor blueColor] CGColor]];

I am hoping someone can teach me and help to turn this into a functional learning experience! Thanks for your help.

4

2 回答 2

1

将它们存储到数组中并传递给函数

是的。这是一种选择:

- (void)makeImageViewsOval:(NSArray*)imgArray {
    for (UIImageView *currentImage in imgArray) {
        CALayer *A = currentImage.layer;
        [A setMasksToBounds:YES];
        [A setCornerRadius:31.0];
        [A setBorderWidth:2.5];
        [A setBorderColor:[[UIColor blueColor] CGColor]];
    }
}

然后,您可以像这样轻松地提供您UIImageView的 s:

[self makeImageViewsOval:@[imgView1, imgView2, imgView3]];
于 2013-10-02T19:55:58.087 回答
0

在您添加所有图像之前NSArray,例如:

NSArray *images = [[NSArray alloc] initWithObjects: img1, img2, img3, img4, img5, nil];

然后你只需要制作一个类似的方法

-(void)imagesTrasformerByArray:(NSArray *)images{

    for(UIImageView *image in images){

    CALayer *A = [imgage layer];
    [A setMasksToBounds:YES];
    [A setCornerRadius:31.0];
    [A setBorderWidth:2.5];
    [A setBorderColor:[[UIColor blueColor] CGColor]];

    }


}
于 2013-10-02T19:56:09.353 回答