2013-03-22 63 views
0

我有一个滚动视图,并在那里动态显示图像的for循环...现在我想让它的边界滚动视图图像..我是这个xcode environment.i全新的东西,但Google不能理解它将如何done..my代码如下如何在xcode 4.5中的UIscrollview中显示图像边框?

scr.contentSize = CGSizeMake(0, 0); 
      for(int i=1;i<6;i++) 
      { 
       UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(x+0, 0, 320, 460)]; 
       [image setImage:[UIImage imageNamed:[NSString stringWithFormat:@"n5%d.png",i]]]; 
       [scr addSubview:image]; 
       x+=320; 
       UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; 
       tapGesture.numberOfTapsRequired = 1; 
       tapGesture.delegate = self; 
       image.userInteractionEnabled = YES; 
       [image addGestureRecognizer:tapGesture]; 
      } 
      [email protected]"Bhavik"; 
      [self.view addSubview:scr]; 
      [email protected]"krish"; 
      scr.pagingEnabled=YES; 
      scr.contentSize = CGSizeMake(320*5, 300); 

谁能给我提供了一些解释建议所以它会在将来也帮助..

+0

做你想做的边框添加到ImageView的? – 2013-03-22 06:54:24

+0

是的,我想添加边界到UIImageView – 2013-03-22 06:55:00

+0

然后Rajan的答案会做到这一点 – 2013-03-22 06:56:10

回答

2
// *** To add Framework *** 
// Step 1 : Select your project From Navigation Panel on the left side 
// Step 2 : On the Right Panel you will get details, Select Summery tab if not selected 
// Step 3 : Scroll Down, you will find "Linked frameworks and Libraries", expand it. 
// Step 4 : Press "+" button to add framework, Pick "QuartzCore.framework" framework from list and ADD it. 

// Now import it to your file and do following code to add border 

// First of all add QuartzCore.framework, 
// Then import #import <QuartzCore/QuartzCore.h> your file 

UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(x+0, 0, 320, 460)]; 
[image setImage:[UIImage imageNamed:[NSString stringWithFormat:@"n5%d.png",i]]]; 

// Set border color and width of image 
[image.layer setBorderColor:[UIColor whiteColor].CGColor]; 
[image.layer setBorderWidth:2.0f]; 

[scr addSubview:image]; 
+0

嗯....多数民众赞成在很大的帮助...回答很好的解释..谢谢 – 2013-03-22 07:03:57

+0

谢谢bhavik。随意问你的任何疑问。 – 2013-03-22 07:06:47

+0

oh.thanx ...你也来自艾哈迈达巴德..那是gr8? – 2013-03-22 07:08:09

4

可以以这种方式做到这一点:

//you need this import 
#import <QuartzCore/QuartzCore.h> 

[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]]; 
[imageView.layer setBorderWidth: 2.0]; 
+0

哦好吧...我刚才尝试过...但忘记导入上述头文件..silly错误...刚开始在iOS上开发更早.. – 2013-03-22 06:57:41

+0

@BhavikKama享受派对! – 2013-03-22 06:58:15

+0

你可以告诉我更多关于这个边界..如果我想使用阴影和所有这一切? – 2013-03-22 06:59:06

1

试试这个:

UIImageView *imageView = [UIImageView alloc]init]; 
imageView.layer.masksToBounds = YES; 
imageView.layer.borderColor = [UIColor blackColor].CGColor; 
imageView.layer.borderWidth = 1; 

在导入之前#import <QuartzCore/CALayer.h>框架。

+0

thanx这工作tooo – 2013-03-22 06:58:10

1

给予边框UIImageView

添加#import "QuartzCore/QuartzCore.h" fram工作。

imgView.layer.cornerRadius = 15.0; // set as you want. 
imgView.layer.borderColor = [UIColor lightGrayColor].CGColor; // set color as you want. 
imgView.layer.borderWidth = 1.0; // set as you want.