【发布时间】:2012-04-17 09:26:42
【问题描述】:
我正在使用 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 方法被调用,但它在屏幕上什么也没画。有谁知道这是什么问题或我该如何解决?
我想将它从UIView 更改为UIImageView 的原因是我想设置图像并更改颜色。当我使用UIView 并使用
self.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"0010.png"]];
图片不适合查看。整个图像只有一部分是可见的。即使我将内容模式更改为UIViewContentModeScaleToFill,整个图像也不可见。
【问题讨论】:
-
您所说的“使用 uiview 但不使用 uiview 是什么意思?”。 iOS中有多少种UIView?你能帮我吗我只知道一个 UIView
标签: iphone uiview uiimageview uibezierpath