UIImageView 的contentMode属性
2016-03-16 15:25
621 查看
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, 按比例 // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, 填充 // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};
UIImageView * images = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images.frame = CGRectMake(100, 150, 50, 10);
images.layer.borderColor = [[UIColor greenColor]CGColor];
images.layer.borderWidth = 1;
UIImageView * images1 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images1.frame = CGRectMake(100, 170, 50, 10);
images1.layer.borderColor = [[UIColor greenColor]CGColor];
images1.layer.borderWidth = 1;
images1.contentMode = UIViewContentModeScaleAspectFill;
//UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
UIImageView * images2 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images2.frame = CGRectMake(100, 190, 50, 10);
images2.layer.borderColor = [[UIColor greenColor]CGColor];
images2.layer.borderWidth = 1;
images2.contentMode = UIViewContentModeScaleAspectFit;//采用这种
//UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。
UIImageView * images3 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images3.frame = CGRectMake(100, 210, 50, 10);
images3.layer.borderColor = [[UIColor greenColor]CGColor];
images3.layer.borderWidth = 1;
images3.contentMode = UIViewContentModeScaleToFill;
//UIViewContentModeScaleToFill属性会导致图片变形。
[self.view addSubview:images];
[self.view addSubview:images1];
[self.view addSubview:images2];
[self.view addSubview:images3];
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit, 按比例 // contents scaled to fit with fixed aspect. remainder is transparent
UIViewContentModeScaleAspectFill, 填充 // contents scaled to fill with fixed aspect. some portion of content may be clipped.
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};
UIImageView * images = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images.frame = CGRectMake(100, 150, 50, 10);
images.layer.borderColor = [[UIColor greenColor]CGColor];
images.layer.borderWidth = 1;
UIImageView * images1 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images1.frame = CGRectMake(100, 170, 50, 10);
images1.layer.borderColor = [[UIColor greenColor]CGColor];
images1.layer.borderWidth = 1;
images1.contentMode = UIViewContentModeScaleAspectFill;
//UIViewContentModeScaleAspectFill也会证图片比例不变,但是是填充整个ImageView的,可能只有部分图片显示出来。
UIImageView * images2 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images2.frame = CGRectMake(100, 190, 50, 10);
images2.layer.borderColor = [[UIColor greenColor]CGColor];
images2.layer.borderWidth = 1;
images2.contentMode = UIViewContentModeScaleAspectFit;//采用这种
//UIViewContentModeScaleAspectFit会保证图片比例不变,而且全部显示在ImageView中,这意味着ImageView会有部分空白。
UIImageView * images3 = [[UIImageView alloc]initWithImage:[UIImage bloc_imageNamed:@"bloc_imge_moreAward_use_phone_title"]];
images3.frame = CGRectMake(100, 210, 50, 10);
images3.layer.borderColor = [[UIColor greenColor]CGColor];
images3.layer.borderWidth = 1;
images3.contentMode = UIViewContentModeScaleToFill;
//UIViewContentModeScaleToFill属性会导致图片变形。
[self.view addSubview:images];
[self.view addSubview:images1];
[self.view addSubview:images2];
[self.view addSubview:images3];
相关文章推荐
- Android:SystemUi有关notification
- 随机数生成 arc4random_uniform(_:UInt32) ->UInt32
- 堵塞队列--BlockingQueue
- Ngui 左右滑动
- 解决的方法:warning: Clock skew detected. Your build may be incomplete.
- Xcode中的Version和Build的区别
- 导航栏颜色及UIBarButtonItem 的设置
- iOS This certificate has an invalid issuer
- 给UI控件画边框
- 从keyPressEvent按键事件中获取QKeySequence
- iOS开发中使用UIScrollView实现无限循环的图片浏览器
- mysql中key 、primary key 、unique key 与index区别
- UITableViewCell滑动删除及移动
- Swfit UITableView的使用(六)
- UICollectionView Section 纯代码代码控制 HeaderView和FooterView的显示,uicollectionview
- StringBuilder和String的区别
- Activity.runOnUiThread(Runnable)简单介绍
- uva 11195 Another queen (用状态压缩解决N后问题)
- php中使用$_REQUEST需要注意的一个问题
- Django View Request和Response