Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make UIView a Circle in Swift [duplicate]

I have tried Googling my problem but cannot seem to find anything anywhere! Basically I have a UIView which retrieves a Users Facebook Photo once they log into my app. At the moment it is a square, but I cannot figure out at all how to turn the UIView into a circle... Any help would be greatly appreciated, I am still learning! -Alex

This Just connects it to the UIView..

@IBOutlet var profilePictureView : FBProfilePictureView!

This sets the View as the Users FB Profile Photo

profilePictureView.profileID = user.objectID

And in app delegate.swift

FBProfilePictureView.self

Thats all the code, I set the UIView's class to be FBProfilePictureView.

like image 385
alexgarbz Avatar asked Sep 09 '25 16:09

alexgarbz


2 Answers

You can try this

 profilePictureView.layer.cornerRadius = profilePictureView.frame.size.width/2
 profilePictureView.clipsToBounds = true

 profilePictureView.layer.borderColor = UIColor.whiteColor().CGColor
 profilePictureView.layer.borderWidth = 5.0
like image 184
rakeshbs Avatar answered Sep 12 '25 06:09

rakeshbs


Try defining a UIBezier path as a circle and then add it as a clip to your view:

let circle = UIBezierPath(arcCenter: (CGPoint), radius: (CGFloat), startAngle: 0, endAngle: 2*M_PI)

double check, but I think arcCenter is in your superview's co-ordinate system.

To add it as a clipping path, I think it's just: (You'll have to check the docs for details):

circle.addClip()
like image 45
Steve Ives Avatar answered Sep 12 '25 06:09

Steve Ives