zoukankan      html  css  js  c++  java
  • UI: UIImageView

    以图片的实际宽和高显示在屏幕上。 
    UIImage *macBookAir = [UIImage imageNamed:@"MacBookAir.png"]; 
    //initWithImage:
    self.myImageView = [[UIImageView alloc] initWithImage:macBookAir];

    给定大小initWithFrame :

    self.myImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    我们设定了这个图片的 frame,但是这个图片显示在 image view 中有时是不准确的(拉长等等)。
    我们可以通过设置图片视图的 contentMode 属性来改善这个问题。这个属性属于 UIContentMode 类型。如下所示。 
    typedef enum { 
    UIViewContentModeScaleToFill, 
    UIViewContentModeScaleAspectFit,
    UIViewContentModeScaleAspectFill, 
    UIViewContentModeRedraw, 
    UIViewContentModeCenter, 
    UIViewContentModeTop, 
    UIViewContentModeBottom, 
    UIViewContentModeLeft, 
    UIViewContentModeRight,
    UIViewContentModeTopLeft, 
    UIViewContentModeTopRight, 
    UIViewContentModeBottomLeft, 
    UIViewContentModeBottomRight,
    } UIViewContentMode;
    下面对 UIViewContentMode 中最有用的几个值进行解释:
    UIViewContentModeScaleToFill

    这个值会将 image view 里的图片进行缩放,以充满整个 image view。 

    UIViewContentModeScaleAspectFit

    这个值会确保 image view 里的图片有正确的长宽比,并且会确保图片适应 image view 的边界。

    UIViewContentModeScaleAspectFill

    这个值会确保 image view 里的图片有正确的长宽比,并且使图片充满整个图片视图的 边界。为了能使这个值正常工作,确保将 clipsToBounds 这个属性值设置为 YES。 

    self.myImageView.contentMode = UIViewContentModeScaleAspectFit;
  • 相关阅读:
    vue this,$set方法
    表格的拖拽排序功能---应用splice方法
    ES6方法的特性总结
    template functional
    scrollTop, offsetTop, pageYOffset, scrollY 的区别
    Sass @mixin 与 @include
    关于Vue中props的详解
    前端开发工具宝典
    前端js开发常用的60种工具方法
    element ui table表格里面插槽的使用方法
  • 原文地址:https://www.cnblogs.com/safiri/p/4023742.html
Copyright © 2011-2022 走看看