Want to display image in the circle it is possible and how

陌路散爱 提交于 2019-12-25 01:03:28

问题


hi i want to display image in the circle not in the rectangle and all this will display in the tableview


回答1:


You have to #import <QuartzCore/QuartzCore.h> and add a cornerRadius to your imageView [yourImageView.layer setCornerRadius:yourImageView.frame.size.width/2] maybe you have to add [yourImageView setClipsToBounds:YES], but i am not sure about this.




回答2:


One way of doing this is to create a subclass of NSView.

Then in you override drawrect: methods to do your custom drawing. You start by drawing your image in your defined frame. After that, you can either draw over, in the the same frame, an image of a rectangle with a transparent circle in the middle or use NSBezierPath to construct a similar rectangle.

The color of this rectangle, except the transparent circle in the middle, is the same as the background color of the enclosing view.




回答3:


Or you can use -drawRect method:

- (void)drawRect:(CGRect)rect
{
    CGRect aRectangle = CGRectMake(0.0f, 0.0f, 40.0f, 40.0f); //size of image frame
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:aRectangle];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    UIColor *imageColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImage.png"]];
    [imageColor setFill];
    [path fill];
}

First of all you need to create your own class inherited from UIView (for example) and put this code into your drawRect.




回答4:


Create the image as a PNG and add a transparency layer. Select the area around the circle and make it transparent. Then when the image is loaded in the UIImageView, it will appear as just a circle.

For example:




回答5:


Alternative is to use CICircularWrap . It wraps an image around a transparent circle.

For example like this:

then u can use UIImageView's layer setCornerRadius to perfect circular image



来源:https://stackoverflow.com/questions/12173386/want-to-display-image-in-the-circle-it-is-possible-and-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!