简体   繁体   中英

How can we round the UIImageView using autolayouts

In my project have added image on my tableview cell, for this I have tried some code but that's not working, what did I do here wrong?

Here my main requirement is I want to round that image (as like circle format).

My code:

 Personimage = [[UIImageView alloc]init];
   Personimage.image = [UIImage imageNamed:@"ram.jpeg"];
   Personimage.translatesAutoresizingMaskIntoConstraints = NO;
   [Cell.contentView addSubview:Personimage];

   //Applying autolayouts

    NSDictionary * viewsDic = NSDictionaryOfVariableBindings(Personimage)

     [Cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[Personimage(80)]"
                                                                                 options:0
                                                                                 metrics:nil
                                                                                   views:viewsDic]];

        [Cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[Personimage(80)]"
                                                                                 options:0
                                                                                 metrics:nil
                                                                                   views:viewsDic]];
}

-(Void)ViewDidAppear
{
  Personimage.layer.cornerRadius = Personimage.frame.size.width / 2;
  Personimage.layer.borderWidth = 3.0f;
  Personimage.layer.borderColor = [UIColor whiteColor].CGColor;
  Personimage.clipsToBounds = YES;
}

After applying auto-layouts i have kept image"round" properties in viewDidAppear method but still it's not working what did i do wrong here? please help me someone

You can use this code to round the UIImageView

 imgView.layer.cornerRadius = imgView.frame.size.width / 2;
 imgView.clipsToBounds = YES;

The property clipsToBounds is a Bool value, change its value from YES to true will work.

Have fun with Swift!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM