I am using UITableViewCell as UITableView Header. I am using the below code to make rounded corners for UIImageView.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if(section==0){
static NSString *simpleTableIdentifier = @"ContactDetailsHeaderTableViewCell";
ContactDetailsHeaderTableViewCell *cell = (ContactDetailsHeaderTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactDetailsHeaderTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
..................
.................
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
//rounded corners
cell.profilePicImgView.clipsToBounds = YES;
UIGraphicsBeginImageContextWithOptions(cell.profilePicImgView.bounds.size, NO, 1.0);
// Add a clip before drawing anything, in the shape of an rounded rect
[[UIBezierPath bezierPathWithRoundedRect:cell.profilePicImgView.bounds
cornerRadius:60.0] addClip];
// Draw your image
[img drawInRect:cell.profilePicImgView.bounds];
// Get the image, here setting the UIImageView image
cell.profilePicImgView.image = UIGraphicsGetImageFromCurrentImageContext();
// end drawing
UIGraphicsEndImageContext();
.............
.............
}
Below is the output
The image inside the UIImageView is stretching, if i am not using the rounded corners then the image is looking properly. I have tried lot of code sample from StackOverflow but none of them are working.
Figured out the issue, posting the answer so it may help others. Its not related to rounded corners code. The rounded corners code is working fine. In UIImagePickerController i have set allowsEditing = YES
but in didFinishPickingMediaWithInfo
i was using UIImagePickerControllerOriginalImage
so later i changed it to UIImagePickerControllerEditedImage
. Now its working fine. I am able to get the rounded corners image without any stretch.
-(void)capturePhoto{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
/* earlier i have used UIImagePickerControllerOriginalImage in the place of UIImagePickerControllerEditedImage so it was not working properly*/
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
............
............
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments