4
클리핑을 통해 둥글게하려는 정사각형 이미지가 40x40이지만 이미지 주위에 검정색 5 픽셀 테두리를 넣을 수도 있습니다.정사각형 이미지를 원으로 마스킹하고 이미지 주위에 검은 색 테두리를 넣을 수 있습니다.
나는 그 지금 라운드
UIImage *image = self.imageView.image;
CGSize imageSize = image.size;
CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
// Create the clipping path and add it
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:imageRect];
[path addClip];
[image drawInRect:imageRect];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = roundedImage;
있도록 사각형 이미지를 마스킹 한 다음이하지만 지금은 주위에 둥근 테두리를 추가해야합니다. 새로운 경로가 필요합니까? 아니면 위의 코드에서 하나를 택할 수 있습니까?
[imageView.layer setBorderColor : [[UIColor blackColor ] CGColor]]; [imageView.layer setBorderWidth : 1.0]; [imageView.layer setCornerRadius : 10.0f]; 이런 식으로 경계를 설정하면 어떻게 될까요? 작동 되나요? – iDev
이 코드는 잘린 이미지가 아닌'imageView' 레이어에 테두리를 추가합니다. – atxe
imgView.clipsToBounds = YES로 설정하면 작동합니다. – Allfocus