ボタンをクリックした後に円を描こうとしています。私は矩形を作成することはできますが、円を描くことはできません。xcodeでボタンをクリックした後に円を描く
はこれを作るための方法があります:
-(IBAction) buttonTouched
{
}
コールまたはこれが動作するように合図:任意の入力のための
- (void)drawRect:(CGRect)rect
{
}
ありがとう!
*編集* * 申し訳ありませんが、それは働いていません。私が間違っていることがわからない:
1) "test"という新しいビューベースのプロジェクトを作成しました。 2) "view"というObjective-CクラスのUIViewを作成しました。 3)IBがビュー上にボタンをドラッグし、それを "buttonTouched"にリンクしました - 内部をタッチしました。
testViewController.h
#import <UIKit/UIKit.h>
#import "view.h"
@interface testViewController : UIViewController {
}
-(IBAction) buttonTouched;
@end
testViewController.m
#import "testViewController.h"
#import "view.h"
@implementation testViewController
- (IBAction)buttonTouched {
[[self view] setNeedsDisplay];
}
view.m
#import "view.h"
@implementation view
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextFillEllipseInRect(contextRef, CGRectMake(100, 100, 25, 25));
CGContextSetRGBFillColor(contextRef, 0, 0, 255, 1.0);
CGContextStrokeEllipseInRect(contextRef, CGRectMake(100, 100, 25, 25));
CGContextSetRGBFillColor(contextRef, 0, 0, 255, 1.0);
}
- (void)dealloc {
[super dealloc];
}
@end
を確認してください、あなたは何を試してみましたか?長方形を作成するコードを表示します。サークルを作成しようとするコードを表示します。 –