UIImageView设置为圆形

时间:2024-07-04 13:06:14

  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];