UIImageView设置为圆形

  

  CGFloat headimageX = self.view.frame.size.width * 0.2;

CGFloat headimageY = self.view.frame.size.height * 0.25;

CGFloat headimageW = self.view.frame.size.width * 0.6;

CGFloat headimageH = headimageW;

UIImageView *headimageview  = [[UIImageView alloc] init];

headimageview.frame = CGRectMake(headimageX, headimageY, headimageW, headimageH);

//这句必须写

headimageview.layer.masksToBounds = YES;

headimageview.layer.cornerRadius = headimageW * 0.5;

headimageview.image = [UIImage imageNamed:@"1"];

[self.view addSubview:headimageview];

时间: 2024-07-30 20:57:27

UIImageView设置为圆形的相关文章

iOS UIImageView设置为圆形

UIImageView设置为圆形的方法: _Image.layer.masksToBounds = YES; _Image.layer.cornerRadius = self.Image.frame.size.width / 2; 设置加载本地图片的方法: _Image.image = [UIImage imageNamed:@"Image"];//图片“Image”为xcassets里的set名称

Blend 设置一个圆形的按钮

原文:Blend 设置一个圆形的按钮 1)画一个圆形 右击构成控件 3)选择button  当然如果想做成别的控件 都可以 4)我们有了一个button 5)做动画 6)定义触发器 7)定义事件 效果 原文地址:https://www.cnblogs.com/lonelyxmas/p/12075810.html

Android实现本地上传图片并设置为圆形头像

我们在做项目的时候会用到圆形的图片,比如用户头像,类似QQ.用户在用QQ更换头像的时候,上传的图片都是矩形的,但显示的时候确是圆形的.那么这是如何实现的呢,下面我们就来探讨下吧. 先从本地把图片上传到服务器,然后根据URL把头像处理成圆形头像. 因为上传图片用到bmob的平台,所以要到bmob(http://www.bmob.cn)申请密钥. 效果图: 核心代码如下: public class MainActivity extends Activity {        private Imag

UIImageView设置手势无效

在给UIImageView添加手势时,发现不起作用,最终发现是由于我没有设置 User Interaction Enabled和Multiple Touch NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"view_register_top" owner:self options:nil]; UIView *topView = views.firstObject; CGRect tframe = CGRectMake(top

UIImageView 使图片圆形的方法

UIImageView 圆形的两种方法 1.cornerRadius (tableView,collectionView尽量避免使用,影响性能) //想要圆角 cornerRadius必须是 imageview高的一半 imageView.layer.cornerRadius = imageView.frame.size.height/2; imageView.layer.masksToBounds = YES; 2.图片本身就是圆形

UIButton 设置为圆形,并且使用图片(UIImage)当做背景

-(UIButton *)shareButtonWithIcon:(NSString *)iconName { UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(100, 100, 2 * 50, 2 * 50); // Circle background UIView *circle = [[UIView alloc] initWithFrame:CGRectMak

iOS开发-UIImageView高效设置Radius

圆角的设置在iOS中随处可见,开发的时候也很方便,但是有的时候如果一个页面有大量的需要设置圆角的图片,容易产生性能问题,UIImageView ios9.0之前设置圆角是会产生离屏渲染的,9.0之后不会产生离屏渲染 因此需要日常设置圆角的方法上加一些改动: 1.最简单的图片圆角设置: self.imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100,200, 100, 100)]; [self.imageView setImage:[

ios之如何让图片显示成圆形的样式/设置控件边框大小以及颜色

比如说QQ登陆头像显示出来的就是圆形的,但实际上它的图片并非就是圆形,而是通过对layer层进行绘制而成的.说到layer每个控件都会有layer层属性所以可以把任意的控件都可以设置成圆形,或是椭圆型看项目需要而定 UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"头像.png"]]; imageView.frame = CGRectMake(100, 100, 100, 1

将UIImageView改成圆角和圆形

1.绘制圆角 cornerView.layer.cornerRadius = 20; cornerView.layer.masksToBounds = YES; masksToBounds防止子元素溢出父视图. 如果一个正方形要设置成圆形,代码为: cornerView.layer.cornerRadius = cornerView.frame.size.height/2; cornerView.layer.masksToBounds = YES; 2.绘制边框 borderView.layer