我有一个数组中的图像,当我在视图中显示这些图像时,它应该出现在边框中。如何设置边框颜色?
for(UIImage *img in imagesArray)
{
//for bordercolor
}
我有一个数组中的图像,当我在视图中显示这些图像时,它应该出现在边框中。如何设置边框颜色?
for(UIImage *img in imagesArray)
{
//for bordercolor
}
首先从Build Phases => Link Binary with Libraries => Add button(+)QuartzCore.framework
在您的项目中添加框架,然后将其文件导入您的类中,如下所示...
#import <QuartzCore/QuartzCore.h>
并使用下面的代码设置颜色..
yourImageView.layer.borderWidth = 2.0;
yourImageView.layer.borderColor= [UIColor redColor].CGColor;
更新:
-(IBAction)lockword:(id)sender {
for (UIImage *img3 in imagesArray) {
UIImageView *imgview1=[[UIImageView alloc]initWithImage:img3];
imgview1.layer.borderWidth = 2.0;
imgview1.layer.borderColor = [UIColor redColor].CGColor;
[imgview1 release];
// your other code write here
// Add this UIImageView as a subview of your view with its frame...
}
}
#import <QuartzCore/QuartzCore.h>
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
要允许编辑 imageview 的边框颜色属性,您需要添加Quartzcore 框架 Add it from : Link Binary with Libraries 选项,然后在要更改边框颜色的地方编写以下代码:
[imageview.layer setBorderWidth:2.0]; // set the border width to any value you want so that your bordercolor would appear accordingly
[imageview.layer setBorderColor:[[UIColor blueColor].CGColor]; // set the color to whatever background color you want to set to your image