1つの画像に長方形を描きたいのですが、それはどのようにするのですか? どうすればいいですか?uiimageビューと長方形
4
A
答えて
1
-(IBAction)Handeltap:(UIGestureRecognizer *)sender
{
if(sender.state==UIGestureRecognizerStateBegan)
{
tapPoint1 = [sender locationInView:sender.view];
NSLog(@"UIGestureRecognizerStateBegan and x=%d and y=%d",(int)tapPoint1.x,(int)tapPoint1.y);
img1=[[UIImageView alloc]initWithImage:nil];
[img1 setBackgroundColor:[UIColor lightTextColor]];
CGRect rect1=CGRectMake((float)tapPoint1.x,(float)tapPoint1.y,50,20);
NSLog(@"rect=%f and %f and %f and %f",rect1.origin.x,rect1.origin.y,rect1.size.width,rect1.size.height);
[img1 setFrame:rect1];
[self.view addSubview:img1];
[self.view bringSubviewToFront:img1];
}
if(sender.state==UIGestureRecognizerStateChanged)
{tapPoint2 = [sender locationInView:sender.view];
// NSLog(@"UIGestureRecognizerStateChanged and x=%d and y=%d",(int)tapPoint.x,(int)tapPoint.y);
[img1 setFrame:CGRectMake(img1.frame.origin.x,img1.frame.origin.y,(float)tapPoint2.x-img1.frame.origin.x,(float)tapPoint2.y-img1.frame.origin.y)];
}
if(sender.state==UIGestureRecognizerStateEnded)
{
tapPoint2 = [sender locationInView:sender.view];
NSLog(@"UIGestureRecognizerStateEnded and x=%d and y=%d",(int)tapPoint2.x,(int)tapPoint2.y);
[img1 setFrame:CGRectMake(img1.frame.origin.x,img1.frame.origin.y,(float)tapPoint2.x-img1.frame.origin.x,(float)tapPoint2.y-img1.frame.origin.y)];
}
}
タップジェスチャーを追加し、この
UILongPressGestureRecognizer *ges11=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(Handeltap:)];
[self.view addGestureRecognizer:ges11];
を貼り付け
私を助けるためのタンク..
1
0
あなたはちょうどあなたがこのようにそれを行うことができ、画像にシンプルな色付きの矩形を追加したい場合は、次の
UIImage *imageFile = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"myImageFile" ofType:@"jpg"]];
UIImageView *myImageFileView = [[UIImageView alloc] initWithImage:imageFile];
myImageFileView.frame = CGRectMake(0, 0, 320, 480); //size of image view
[self.view addsubview:myImageFileView]; //I assume this is within a view controller .m
UIView *rectangle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; //A rectangle at point (0, 0) 50x50 in size.
rectangle.backgroundColor = [UIColor redColor]; //color the rectangle
[myImage addSubview:rectangle]; //add the rectangle to your image
[rectangle release];
[imageFile release];
[myImageFileView release];
+0
実際に私はビュー上に1つの画像を持っています。今私はその画像上に透明な矩形を1つ描きたい。 – GameLoading
+0
rectangle.backgroundColor = [UIColor clearcolor]; – Zigglzworth
関連する問題
- 1. 長方形のビューのパーフェクトラウンドコーナー
- 2. UIimageビューを他のUIimageビューと同じに設定する
- 3. uipickerビューの整数とuiimage
- 4. 固定長方形の長方形パッキング
- 5. Xcodeの「フレーム長方形」と「レイアウト長方形」
- 6. SVG長方形とパスグラデーション
- 7. 長方形イベントプログラム
- 8. 長方形
- 9. 長方形/楕円形プログラム
- 10. 三角形UIImageの作成方法
- 11. コアグラフィックスとUIImageで四角形を描画
- 12. Pythonの:長方形
- 13. 長方形の幅
- 14. TreeSet長方形コンパレータ
- 15. 長方形/コンプレックスフロートエラー/パイソン
- 16. JavaFX ActionEvent長方形
- 17. MFCの長方形
- 18. wpf3d長方形ヒットテスト
- 19. Androidの長方形
- 20. Matlab - 長方形関数を使用しないプロット長方形
- 21. UIImageビューへのアニメーション(objective-c)
- 22. 3Dのレイと正方形/長方形の交差
- 23. n個の長方形のn個の長方形をn個の大きな長方形に合わせる
- 24. UIImageボタン(四角形ボタン)
- 25. 長方形とOpacityMaskのWPFボタン
- 26. 描画長方形と楕円
- 27. 不規則な長方形の形
- 28. カスタム非長方形ボタン三角形
- 29. iPhone - 長方形の交差
- 30. 図面の長方形
何かをイメージの上に描くことを意味しますか? – shannoga
はい私はイメージを描きたい。私は別のイメージを置くことができますか、それは私にとって問題ではないが、そのイメージをどのように描くのですか? – GameLoading