Uİİmage üzerinde yuvarlak Köşeler
Kişiler uygulamasında kişi ımages a la köşeleri yuvarlatılmış iPhone kullanarak, üzerinde resimler çizmeye çalışıyorum. Genellikle çalışan kod var, ama bazen içindeki UİİmageEXEC_BAD_ACCESS
- KERN_INVALID_ADDRESS
bir rutinleri ile çizim çöker. Bu birkaç hafta önce sordum cropping question ile ilgili olabileceğini düşündüm, ama kırpma yolu doğru kuruyorum inanıyorum.
İşte kullanıyorum kod - kaza değil, sonuç iyi görünüyor ve kimse benzer bir görünüm elde etmek isteyenler, kodu ödünç almak ücretsizdir.
- (UIImage *)borderedImageWithRect: (CGRect)dstRect radius:(CGFloat)radius {
UIImage *maskedImage = nil;
radius = MIN(radius, .5 * MIN(CGRectGetWidth(dstRect), CGRectGetHeight(dstRect)));
CGRect interiorRect = CGRectInset(dstRect, radius, radius);
UIGraphicsBeginImageContext(dstRect.size);
CGContextRef maskedContextRef = UIGraphicsGetCurrentContext();
CGContextSaveGState(maskedContextRef);
CGMutablePathRef borderPath = CGPathCreateMutable();
CGPathAddArc(borderPath, NULL, CGRectGetMinX(interiorRect), CGRectGetMinY(interiorRect), radius, PNDegreeToRadian(180), PNDegreeToRadian(270), NO);
CGPathAddArc(borderPath, NULL, CGRectGetMaxX(interiorRect), CGRectGetMinY(interiorRect), radius, PNDegreeToRadian(270.0), PNDegreeToRadian(360.0), NO);
CGPathAddArc(borderPath, NULL, CGRectGetMaxX(interiorRect), CGRectGetMaxY(interiorRect), radius, PNDegreeToRadian(0.0), PNDegreeToRadian(90.0), NO);
CGPathAddArc(borderPath, NULL, CGRectGetMinX(interiorRect), CGRectGetMaxY(interiorRect), radius, PNDegreeToRadian(90.0), PNDegreeToRadian(180.0), NO);
CGContextBeginPath(maskedContextRef);
CGContextAddPath(maskedContextRef, borderPath);
CGContextClosePath(maskedContextRef);
CGContextClip(maskedContextRef);
[self drawInRect: dstRect];
maskedImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextRestoreGState(maskedContextRef);
UIGraphicsEndImageContext();
return maskedImage;
}
ve burada kaza günlüğü. Bu kazalardan ne zaman başım sıkışsa aynı görünüyor
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x6e2e6181 Crashed Thread: 0 Thread 0 Crashed: 0 com.apple.CoreGraphics 0x30fe56d8 CGGStateGetRenderingIntent 4 1 libRIP.A.dylib 0x33c4a7d8 ripc_RenderImage 104 2 libRIP.A.dylib 0x33c51868 ripc_DrawImage 3860 3 com.apple.CoreGraphics 0x30fecad4 CGContextDelegateDrawImage 80 4 com.apple.CoreGraphics 0x30feca40 CGContextDrawImage 368 5 UIKit 0x30a6a708 -[UIImage drawInRect:blendMode:alpha:] 1460 6 UIKit 0x30a66904 -[UIImage drawInRect:] 72 7 MyApp 0x0003f8a8 -[UIImage(PNAdditions) borderedImageWithRect:radius:] (UIImage PNAdditions.m:187)
CEVAP
İşte iPhone ve 3.0 bile daha kolay bir yöntem. Görünüm tabanlı her nesne ilişkili bir tabaka vardır. Her katman bir köşe yarıçapı, istediğin şeyi sana verecek.
UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
// You can even add a border
[l setBorderWidth:4.0];
[l setBorderColor:[[UIColor blueColor] CGColor]];
Uİİmage yuvarlak köşeler...
Nasıl yuvarlak köşeler ile EditText ol...
CSS3'border-radius özelliği ve sı...
Tüm UİİmageViews için yuvarlak köşeler...
Explorer gibi yuvarlak köşeler ile seç...