【问题标题】:why the contentmode of the uiimageview did not work?为什么 uiimageview 的 contentmode 不起作用?
【发布时间】:2017-09-28 00:57:26
【问题描述】:

昨天当我编码时,我对 UIImageView 的 contentMode 的问题感到困惑。我想将 UIViewContentModeScaleAspectFill 设置为 UIImageView 但图像溢出 UIImageView 的效果,这是结果:![在此处输入图像描述][ 1]

红框是UIImageView,图中我们可以看到UIImageView的内容溢出了,为什么会这样?

这是代码:![在此处输入图片描述][2]

    UIImageView* copySmall = [[UIImageView alloc] init];
    copySmall.layer.borderColor = [UIColor redColor].CGColor;
    copySmall.layer.borderWidth = 1.f;
    [copySmall setContentMode:UIViewContentModeScaleAspectFill];
    [copySmall setFrame:oriRect];
    [copySmall setImage:imgView.image];

【问题讨论】:

    标签: ios uiimageview contentmode


    【解决方案1】:

    尝试为您的 imageView 设置 clipToBounds = YES

    【讨论】:

    • 谢谢!它解决了我的问题。但是clipTobounds属性用于将子视图剪辑到父视图,仍然很困惑。
    猜你喜欢
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    相关资源
    最近更新 更多