次のコードを使用して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
。UIView
使っUIView
て使うとき
self.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"0010.png"]];
画像が表示に適合しません。画像全体の一部のみが表示されます。コンテンツモードをに変更してUIViewContentModeScaleToFill
も、画像全体が表示されません。