0

我有一个滚动视图,其中正在使用 for 循环动态显示图像……现在我想制作带有边框的滚动视图图像……我在这个 xcode 环境中是全新的。我用谷歌搜索了这些东西,但无法理解它是如何做到的将完成..我的代码如下

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];
            }
            _detailDescriptionLabel.text=@"Bhavik";
            [self.view addSubview:scr];
             self.title=@"krish";
            scr.pagingEnabled=YES;
            scr.contentSize = CGSizeMake(320*5, 300);

任何人都可以给我一些解释的建议,以便将来也有帮助..

4

4 回答 4

4

你可以这样做:

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

[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
于 2013-03-22T06:54:50.743 回答
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];
于 2013-03-22T07:00:53.357 回答
1

试试这个:

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

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

于 2013-03-22T06:56:07.940 回答
1

为给边框UIImageView

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

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.
于 2013-03-22T06:57:58.507 回答