iPhone:将不同尺寸的UIImageView掩盖为方形尺寸 [英] iPhone: Mask UIImageView of differing dimensions into square dimension

查看:55
本文介绍了iPhone:将不同尺寸的UIImageView掩盖为方形尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆比例不同的UIImageViews.100x101的一些是130x121.

I have a bunch of UIImageViews that are in different proportions. Some of 100x101 some are 130x121.

我该如何将它们蒙版为80x80,而不拉伸图像?我基本上只想掩盖每个方块中的一个方块.(有点像Apple的照片缩略图视图)

How can I mask these to 80x80 and NOT stretch the images? I basically just want to mask a square out of each one. (kind of like the Apple's Photo thumbnail view does)

推荐答案

  1. 将图片视图的尺寸设置为80 x 80
  2. 将图像视图的 contentMode 属性设置为 UIViewContentModeScaleAspectFill
  3. 最后,使用以下代码制作圆角,并在实现文件的开头导入 QuartzCore/QuartzCore.h .

CALayer * layer = [myImageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:12.0f];

是的,通过说尺寸,我指的是框架, W H :

Edited: Yes, by saying size I mean frame, the W and H:

这篇关于iPhone:将不同尺寸的UIImageView掩盖为方形尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆