Circle image crop when using UIImagePickerController Swift












1














I need to crop images circle when importing from photo library, just like in the stock contacts app. I found a few solutions but all of them were in Objective-C. I found them hard to translate. Does anyone know a useful swift library or so?










share|improve this question






















  • may be this can be helpful for someone stackoverflow.com/questions/53248609/…
    – Bhavesh.iosDev
    Nov 13 at 4:44
















1














I need to crop images circle when importing from photo library, just like in the stock contacts app. I found a few solutions but all of them were in Objective-C. I found them hard to translate. Does anyone know a useful swift library or so?










share|improve this question






















  • may be this can be helpful for someone stackoverflow.com/questions/53248609/…
    – Bhavesh.iosDev
    Nov 13 at 4:44














1












1








1







I need to crop images circle when importing from photo library, just like in the stock contacts app. I found a few solutions but all of them were in Objective-C. I found them hard to translate. Does anyone know a useful swift library or so?










share|improve this question













I need to crop images circle when importing from photo library, just like in the stock contacts app. I found a few solutions but all of them were in Objective-C. I found them hard to translate. Does anyone know a useful swift library or so?







ios swift uiimageview uiimagepickercontroller






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 31 '16 at 10:46









schoeberlt

9810




9810












  • may be this can be helpful for someone stackoverflow.com/questions/53248609/…
    – Bhavesh.iosDev
    Nov 13 at 4:44


















  • may be this can be helpful for someone stackoverflow.com/questions/53248609/…
    – Bhavesh.iosDev
    Nov 13 at 4:44
















may be this can be helpful for someone stackoverflow.com/questions/53248609/…
– Bhavesh.iosDev
Nov 13 at 4:44




may be this can be helpful for someone stackoverflow.com/questions/53248609/…
– Bhavesh.iosDev
Nov 13 at 4:44












2 Answers
2






active

oldest

votes


















1














this works for me



    profileImage.image = UIImageVar
profileImage.layer.borderWidth = 1
profileImage.layer.borderColor = UIColor.blackColor().CGColor
profileImage.layer.cornerRadius = profileImage.frame.height/2
profileImage.clipsToBounds = true





share|improve this answer

















  • 1




    Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
    – schoeberlt
    Feb 1 '16 at 20:18



















-1














If you're seeking something like Core Graphics, you can take the following for references.



let ctx = UIGraphicsGetCurrentContext()
let image = UIImage(named: "YourImageName")!

// Oval Drawing
let width = image.size.width
let height = image.size.height
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, width, height))
CGContextSaveGState(ctx)
ovalPath.addClip()
image.drawInRect(CGRectMake(0, 0, width, height))
CGContextRestoreGState(ctx)





share|improve this answer





















  • Did you even read the question, OP asks for how to do it like in the stock contacts app.
    – defiant
    Jul 28 at 19:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35112928%2fcircle-image-crop-when-using-uiimagepickercontroller-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














this works for me



    profileImage.image = UIImageVar
profileImage.layer.borderWidth = 1
profileImage.layer.borderColor = UIColor.blackColor().CGColor
profileImage.layer.cornerRadius = profileImage.frame.height/2
profileImage.clipsToBounds = true





share|improve this answer

















  • 1




    Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
    – schoeberlt
    Feb 1 '16 at 20:18
















1














this works for me



    profileImage.image = UIImageVar
profileImage.layer.borderWidth = 1
profileImage.layer.borderColor = UIColor.blackColor().CGColor
profileImage.layer.cornerRadius = profileImage.frame.height/2
profileImage.clipsToBounds = true





share|improve this answer

















  • 1




    Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
    – schoeberlt
    Feb 1 '16 at 20:18














1












1








1






this works for me



    profileImage.image = UIImageVar
profileImage.layer.borderWidth = 1
profileImage.layer.borderColor = UIColor.blackColor().CGColor
profileImage.layer.cornerRadius = profileImage.frame.height/2
profileImage.clipsToBounds = true





share|improve this answer












this works for me



    profileImage.image = UIImageVar
profileImage.layer.borderWidth = 1
profileImage.layer.borderColor = UIColor.blackColor().CGColor
profileImage.layer.cornerRadius = profileImage.frame.height/2
profileImage.clipsToBounds = true






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 31 '16 at 11:21









DeyaEldeen

3,27752250




3,27752250








  • 1




    Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
    – schoeberlt
    Feb 1 '16 at 20:18














  • 1




    Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
    – schoeberlt
    Feb 1 '16 at 20:18








1




1




Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
– schoeberlt
Feb 1 '16 at 20:18




Yeah but the main point is to get that editor view when you see a dark something with a "hole" in it and you can crop the image
– schoeberlt
Feb 1 '16 at 20:18













-1














If you're seeking something like Core Graphics, you can take the following for references.



let ctx = UIGraphicsGetCurrentContext()
let image = UIImage(named: "YourImageName")!

// Oval Drawing
let width = image.size.width
let height = image.size.height
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, width, height))
CGContextSaveGState(ctx)
ovalPath.addClip()
image.drawInRect(CGRectMake(0, 0, width, height))
CGContextRestoreGState(ctx)





share|improve this answer





















  • Did you even read the question, OP asks for how to do it like in the stock contacts app.
    – defiant
    Jul 28 at 19:36
















-1














If you're seeking something like Core Graphics, you can take the following for references.



let ctx = UIGraphicsGetCurrentContext()
let image = UIImage(named: "YourImageName")!

// Oval Drawing
let width = image.size.width
let height = image.size.height
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, width, height))
CGContextSaveGState(ctx)
ovalPath.addClip()
image.drawInRect(CGRectMake(0, 0, width, height))
CGContextRestoreGState(ctx)





share|improve this answer





















  • Did you even read the question, OP asks for how to do it like in the stock contacts app.
    – defiant
    Jul 28 at 19:36














-1












-1








-1






If you're seeking something like Core Graphics, you can take the following for references.



let ctx = UIGraphicsGetCurrentContext()
let image = UIImage(named: "YourImageName")!

// Oval Drawing
let width = image.size.width
let height = image.size.height
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, width, height))
CGContextSaveGState(ctx)
ovalPath.addClip()
image.drawInRect(CGRectMake(0, 0, width, height))
CGContextRestoreGState(ctx)





share|improve this answer












If you're seeking something like Core Graphics, you can take the following for references.



let ctx = UIGraphicsGetCurrentContext()
let image = UIImage(named: "YourImageName")!

// Oval Drawing
let width = image.size.width
let height = image.size.height
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, width, height))
CGContextSaveGState(ctx)
ovalPath.addClip()
image.drawInRect(CGRectMake(0, 0, width, height))
CGContextRestoreGState(ctx)






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 31 '16 at 16:49









Allen

1,4461316




1,4461316












  • Did you even read the question, OP asks for how to do it like in the stock contacts app.
    – defiant
    Jul 28 at 19:36


















  • Did you even read the question, OP asks for how to do it like in the stock contacts app.
    – defiant
    Jul 28 at 19:36
















Did you even read the question, OP asks for how to do it like in the stock contacts app.
– defiant
Jul 28 at 19:36




Did you even read the question, OP asks for how to do it like in the stock contacts app.
– defiant
Jul 28 at 19:36


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35112928%2fcircle-image-crop-when-using-uiimagepickercontroller-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma