2014-12-03 38 views
0

我有一个UIView与一组20 UIImageViews的UIView。事情是:我想给他们每个人一个四舍五入的边界属性,我知道如何做一个再见,但不知道如何做一个循环,因为我需要使用某种查询选择器来检索每个图像控制到一个数组。有没有办法呢?查询选择器舍入UIImageViews的边界

非常感谢。

回答

0

假设你正在使用笔尖或故事板......你可以设置cornerRadius作为意见的关键路径,从而不必在代码中做任何事情:无论是对那些

enter image description here

+0

或者使用'IBInspectable'属性,如果您使用的是Xcode 6. – 2014-12-03 14:36:32

+0

这个解决方案很漂亮,干净,甚至不需要clipsTobounds或maskToBounds。唯一的问题是,xcode不允许通过选择其中的每个人然后添加属性来同时为多个UIImageView添加此属性。无论如何,通过创建一个,应用该属性,然后复制它并粘贴它,问题就解决了。谢谢,你已经在这里打开了我的眼睛... – 2014-12-03 15:45:04

0

仅举您的UIImageView网点为图像1,图像2,图像3 ..... image20等&您可以使用键值编码四舍五入使用的角落循环是这样的:

for(int i=0;i<20;i++) 
{ 
    UIImageView *imageView = ((UIImageView *)[self valueForKey:[NSString stringWithFormat:@"image%d",i+1]]); 
    imageView.layer.cornerRadius = roundf(imageView.frame.size.width/2.0); 
    [imageView.layer setMasksToBounds:YES]; 
    [imageView.layer setBorderWidth:1.0]; 
    [imageView.layer setBorderColor:[[UIColor whiteColor] CGColor]]; 
} 
+0

很好的解决方案谁想要添加borderColor – 2014-12-03 16:41:46

1

把你的IBOutletCollection中的图像视图(如果不使用Interface Builder,则为NSArray)。

+0

这很有用,要么......谢谢 – 2014-12-03 16:45:03