【问题标题】:Using UIImageView's layer.border property to set the border使用 UIImageView 的 layer.border 属性设置边框
【发布时间】:2012-10-10 07:59:42
【问题描述】:

我有一个带有图像的 UIImageView。 initWithFrame:(CGRect)frame 看起来像这样:

#define BORDER_WIDTH_SELECTION 3
#define SELECTED_SCALE_VALUE 1.3

    self.layer.masksToBounds = NO;
    smallFrame_ = frame;
    float newX = self.center.x - ((self.frame.size.width*SELECTED_SCALE_VALUE)*0.5);
    float newY = self.center.y - ((self.frame.size.height*SELECTED_SCALE_VALUE)*0.5);
    bigFrame_ = CGRectMake(newX, newY, self.frame.size.width*SELECTED_SCALE_VALUE, self.frame.size.height*SELECTED_SCALE_VALUE);
    self.layer.borderWidth = BORDER_WIDTH_SELECTION;

然后我触发这个

- (void) setSelected {
    [self makeThumbnailBig];
    self.layer.borderColor = [UIColor colorWithRed:178.0/255.0 green:19.0/255.0 blue:50.0/255.0 alpha:1.0].CGColor;
}

- (void)makeThumbnailBig
{    
    [UIView animateWithDuration:0.2 animations:^{
        self.frame = bigFrame_;
    }];
}

ImageView 正确缩放并绘制红色边框,但随后ImageView 内的image 从左侧边框下方突出大约一两个像素。我已经删除了图片,但这应该可以让您对问题有所了解:

有什么想法吗?

【问题讨论】:

  • 确实是self.layer.masksToBounds = YES;。已删除答案的神秘用户,请返回,以便我接受!
  • 您的问题还有更多问题 :)

标签: iphone objective-c xcode cocoa-touch uiimageview


【解决方案1】:

在你的代码中有一行

self.layer.masksToBounds = NO;

根据问题应该是YES

关于额外像素:

当您通过分割准备图像大小时,您可能会遇到神奇的图像高分辨率优化问题。它首先将分形部分添加到 UIImageView 维度。见Points Versus Pixels

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 2011-09-03
    相关资源
    最近更新 更多