I have created myView which is subclass of UIView
and drawn a circle on the myView. Now i want to display small images within the circle , not outside of the circle. But i got inside circle and outside circle that means the images are displayed on whole myVIew.
I got like as following picture as
But i would like to get as following as
Is it possible or not? Please help me.
Assuming the ellipse is an UIBezierPath
, you can use:
UIImage *patternImage = [UIImage imageNamed:@"thePattern.png"];
UIColor *fillPattern = [UIColor colorWithPatternImage:patternImage];
[fillPattern setFill];
[thePath fill];
EDIT
Fill ellipse created by CGContextAddEllipseInRect
using pattern image:
- (void)drawRect:(CGRect)rect {
CGImageRef patternImage = [UIImage imageNamed:@"file"].CGImage;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(context, CGRectMake(100, 100, 200, 200));
CGContextClip(context);
CGContextDrawTiledImage(context, CGRectMake(20, 20, 48, 36),patternImage);
}
You could try this:
#import <QuartzCore/QuartzCore.h>
and in your code , after making the circle , add the image and set these: myImageView.layer.cornerRadius = x;
myImageView.layer.masksToBounds = TRUE;
This allows you to have rounded corners on your image. And if you calculate the radius to match your circle , you should get the desired look.
Hope this helps.
Cheers,
George
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.