我正在使用以下代码使用 UIBezierPath 制作画笔。
.h File
@interface MyLineDrawingView : UIView
{
UIBezierPath *myPath;
UIColor *brushPattern;
}
@end
.m File
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"0010.png"]];
myPath=[[UIBezierPath alloc]init];
myPath.lineWidth=30;
brushPattern=[UIColor redColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[brushPattern setStroke];
[myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
// [myPath strokeWithBlendMode:kCGBlendModeSaturation alpha:1.0];
// Drawing code
//[myPath stroke];
}
#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath moveToPoint:[mytouch locationInView:self]];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];
[self setNeedsDisplay];
}
它与UIView
. 正如您在上面看到的自定义类继承自UIVIew
. 但是当我进行子类UIImageView
化而不是UIView
我无法绘制任何东西时。Toches 方法被调用,但它在屏幕上什么也没画。有谁知道这有什么问题或我该如何解决?
我想将其更改为UIImageView
from的原因UIView
是我想设置图像并更改颜色。当我使用UIView
和使用
self.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"0010.png"]];
图像不适合查看。整个图像只有一部分是可见的。即使我将内容模式更改为UIViewContentModeScaleToFill
整个图像也不可见。