【问题标题】:How to show image border in UIscrollview in xcode 4.5? [duplicate]如何在 xcode 4.5 的 UIscrollview 中显示图像边框? [复制]
【发布时间】:2013-03-22 06:52:41
【问题描述】:

我有一个滚动视图,其中正在使用 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);

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

【问题讨论】:

  • 你想给imageview添加边框吗?
  • 是的,我想给 UIImageView 添加边框
  • 那么 Rajan 的回答就可以了

标签: ios xcode uiimageview xcode4.5 css


【解决方案1】:

你可以这样做:

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

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

【讨论】:

  • 哦好的...我刚试过...但是忘记导入上面的头文件..愚蠢的错误...刚开始在iOS上开发..
  • @BhavikKama 享受派对!
  • 你能告诉我更多关于这个边框的信息吗?如果我想使用阴影等等?
  • @BhavikKama 使用 Google,StackOverflow 上的一切都已经可用 :) 看看 :)
【解决方案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];

【讨论】:

  • hmmm....这很有帮助...用很好的解释回答..谢谢
  • 谢谢巴维克。如有任何疑问,请随时提出。
  • oh.thanx...你也来自艾哈迈达巴德..那是 gr8?
【解决方案3】:

试试这个:

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

在导入 #import &lt;QuartzCore/CALayer.h&gt; 框架之前。

【讨论】:

  • 谢谢这也有效
【解决方案4】:

为了给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.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 2017-06-24
    • 2015-07-10
    • 1970-01-01
    相关资源
    最近更新 更多