HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 带有边框和圆角的UIImageView,图像从边框边缘弹出大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试用更圆角和白色边框制作UI ImageView,我已经将uIImageView子类化,这是代码

@H_233_5@myUIImageView.h

@interface MyUIImageView : UIImageView

@end
@H_233_5@myUIImageView.m

@implementation MyUIImageView

-(void)layoutSubviews
{
    self.layer.cornerRadius = CGRectGetWidth(self.framE)/2.f;
    self.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.layer.borderWidth = kLineWidth;
    self.layer.masksToBounds = YES;
    self.clipsToBounds = YES;
    self.contentMode = UIViewContentModeScaleAspectFill;
    self.BACkgroundColor = [UIColor colorWithRed:0.82 green:0.82 blue:0.83 alpha:1];
}

@end

这是结果:

看起来很好,但是你可以从这里看到一个问题:

图像从边框边缘弹出,我怎么能避免这个问题?我怎样才能在边界边缘准确切割图像?

解决方法

像这样创建一个自定义边框:

UIImage *image = [UIImage imagenamed:@"spongebob.jpg"];
    UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(30,30,200,200)];
    [borderView.layer setMasksToBounds:YES];
    [borderView.layer setCornerRadius:borderView.frame.size.width/2.0f];
    [borderView setBACkgroundColor:[UIColor whiteColor]];

    int borderWidth = 3.0f;

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(borderWidth,borderWidth,borderView.frame.size.width-borderWidth*2,borderView.frame.size.height-borderWidth*2)];
    [imageView.layer setCornerRadius:imageView.frame.size.width/2.0f];
    [imageView.layer setMasksToBounds:YES];
    [imageView setImage:image];
    [borderView addSubview:imageView];


    [self.view addSubview:borderView];

现在你的图像没有弹出边界.

希望这可以帮助 :)

大佬总结

以上是大佬教程为你收集整理的ios – 带有边框和圆角的UIImageView,图像从边框边缘弹出全部内容,希望文章能够帮你解决ios – 带有边框和圆角的UIImageView,图像从边框边缘弹出所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。