【发布时间】:2023-09-29 02:59:01
【问题描述】:
我正在尝试创建一个圆形 UIImageview。为此,我使用 UIBezierPath 的stroke,颜色为图像。在情节提要中,我将 imageView 的类指定为我的自定义 UIImageView。没用。
这是我的自定义 UIImageView
@implementation CustomImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
UIBezierPath *circularpath = [[UIBezierPath alloc]init];
CGRect Rect = CGRectMake(96, 54, 128, 128);//338
//CGPoint mypoint = CGPointMake(Rect.origin.x + (Rect.size.width / 2), Rect.origin.y + (Rect.size.height / 2));
circularpath = [UIBezierPath bezierPathWithOvalInRect:Rect];
circularpath.lineWidth = 5.0;
[[UIColor blueColor]setStroke];
UIImage *ori = [UIImage imageNamed:@"drogba.jpg"];
UIImage *image = [[UIImage alloc]initWithCGImage:ori.CGImage scale:1.45 orientation:UIImageOrientationUp];
[[UIColor colorWithPatternImage:image]setFill];
NSLog(@"Circular path:%@", circularpath);
[circularpath stroke];
}
这是我在控制器中的声明方式
@property (weak, nonatomic) IBOutlet CustomImageView *dpImage;
【问题讨论】:
-
你为什么使用 UIImageView?为什么不只是 UIView?也许这就是问题
-
我使用 UIImageView 作为它拥有的图像属性
-
所以不要。将您渲染的图像保存在某个本地实例中,并创建您自己的图像属性。
-
@AviTsadok,您有理由相信您的建议会有所帮助吗?我没看到。
-
@vikingosegundo UIImageView 处理的渲染与这里写的不同。如果您需要渲染自己的核心图形代码,UIImageView 不是正确的类。您需要使用常规的 UIView。现在,我不知道这是否是问题所在,但我们需要解决这个问题。
标签: ios objective-c cocoa-touch uiimageview uibezierpath