Rounded UIImageView

uiimageview rounded corners swift
uiimageview circular mask
circular imageview ios swift 4
uiimageview rounded corners storyboard
uiimageview round swift
corner radius circle
image corner radius swift
circle radius in swift

I'm trying to get a rounded UIImageView but it seems to render differently on different devices;

Looks like this on an iPhone Xr:

Looks like this on an iPhone 7:

I have a height constraint of 60 and the following code:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()

    self.userAvatar.layer.cornerRadius = self.userAvatar.frame.height / 2
    self.userAvatar.layer.masksToBounds = false
    self.userAvatar.clipsToBounds = true
    self.userAvatar.layer.borderWidth = 0
}

Any ideas?

It seems to me that you have given the image leading and trailing constraints instead of a fixed width.

To achieve a circle give image view width equal to height. This happens due to different widths of devices.

IOS: create a UIImage or UIImageView with rounded corners, Yes, it is possible. Import the QuartzCore ( #import <QuartzCore/QuartzCore.h> ) header and play with the layer property of the UIImageView . Make UIImageView Corners Rounded I will now use the created in the above Swift code snippet UIImageView and will make its corners rounded by changing the value of CALayer cornerRadius and setting the UIImageView clipsToBounds value to true. myImageView.layer.cornerRadius = 100

If you're managing this view using Interface Builder (i.e. Storyboard or XIB), you can enforce a square shape (which becomes a circle when combined with the rounded corners you already have) for the view directly from there by defining a constraint for its Aspect Ratio. No need to code anything.

Control-drag (like you do to create Outlets, Actions, etc.) from the image view to itself, and the following popup will appear.

Select Aspect Ratio, which will create a constraint matching whatever the view's current ratio is (in this example, it's 15:8). If the view was already square, the constraint created should already be correct.

If not, you can find that constraint by clicking the following icon (for the Size inspector):

From there, you can double-click on that constraint to edit it, and change the Multiplier to 1:1:

In fact, an even easier option is, once you've Control-dragged from the view to itself, hold down Alt/Opt and the option displayed in the popup will change to Aspect Ratio (1:1), meaning you can set it directly from there without even having to edit the constraint.

UIImageView Rounded Corners in Swift, In this Swift tutorial, you will learn how to make UIImageView corners rounded. To learn how to programmatically create new UIImage, add it to� The easiest way is to embed a disabled[!] round-rect [not custom!] button in your view (can even do it all in the Interface Builder) and associate your image with it. The image-setting message is different for UIButton (compared to UIImageView), but the overall kludge works like a charm.

Constrain the height equal to the width.

And, create a simple UIImageView subclass:

class RoundedImageView: UIImageView {
    override func layoutSubviews() {
        super.layoutSubviews()
        layer.cornerRadius = bounds.height / 2
    }
}

The frame can (and will) change based on view lifecycle. By updating the cornerRadius in layoutSubviews() it will keep it "round".

Creating Circular Profile Picture and Rounded Corner Image in iOS, Every view in the UIKit (e.g. UIView, UIImageView) is backed by an instance of the CALayer class (i.e. layer object). The layer object is designed� It works when the imageView is set at Aspect Fill. But when the imageView is set to Aspect Fit mode, and the ratio between imageView and picture are different. The rounded corners effect won’t be able to tell. The background color is set to green for showing the rounded corners.

How to display an image with rounded corners on iOS App using , First of all, let's add an UIImageView Object in our storyboard. Or let's create one programmatically. Below is a function that will programmatically� For Creating a Round Corner image we can use quartzcore. First How to add QuartzCore framework? Click project -Targets ->project ->BuildPhase ->Link Binary with Libraries ->Then click + symbol finally select from list and add it

Circular Image View iOS Tutorial, Image View shapes are square by default. It is possible by using the layer property of the image view to display the image as a circular image. Using a library like this one: Rounded ImageView Library Create a CardView with required corner radius and put ImageView inside it. Add rounding to the image itself.

UIImageView adjustsImageWhenAncestorFocused with rounded , In tvOS all buttons and cells have rounded corners and the nice parallax effect. When you use UICollectionViews you can use a UIImageView as the focusable� If you are using aspectFit AND cornerRadius with clipsToBounds/masksToBounds, you won't get the rounded corners. i.e if you have this. theImageView.contentMode = .scaleAspectFit and . theImageView.layer.cornerRadius = (theImageView.frame.size.height)/2 theImageView.clipsToBounds = true or . theImageView.layer.masksToBounds = true

Comments
  • have you got width constraint or leading and trailing?
  • Please set HEIGHT and WIDTH equal constraint.
  • I think you set the leading and trailing constraint so instead of leading/trailing set height and width only