ios – 如何只向UIImageView添加右边框

前端之家收集整理的这篇文章主要介绍了ios – 如何只向UIImageView添加右边框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想为UI ImageView添加白色边框.我尝试了以下,但它不起作用:
UIImage *image = [UIImage imageNamed:imagePath];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    CGRect rect = imageView.frame;        
    rect.size.width = rect.size.width + 1; // create white right border
    [imageView setBackgroundColor:[UIColor whiteColor]]; 

    imageView.frame = rect;
    [myViewView addSubview:imageView];

解决方法

我现在就这样做了
CALayer *sublayer = [CALayer layer];
        sublayer.backgroundColor = [UIColor whiteColor].CGColor;
        sublayer.frame = CGRectMake(imageView.bounds.size.width,1,imageView.frame.size.height);
        [imageView.layer addSublayer:sublayer];
原文链接:https://www.f2er.com/iOS/331074.html

猜你在找的iOS相关文章