IOS9, xcode7.2, objective-c の初心者です。
ViewController.m の中で、画面中に 長さ100point, 幅 10 point の
線(状態によって、青、黄色、赤)の直線を描きたく、
- (void)viewDidLoad
の次に下記コードを書いたところ、至る所で
「No visible @interface for 'ViewController' declares the selector 'drawRect:inContent:' 」 のようなエラーが出まくります。
どなたか、解決方法、ご教示頂ければ幸いです。
宜しくお願い致します。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
//コンテキストの指定(1)
- (void)setContext:(CGContextRef)context {
if (_context!=NULL) {
CGContextRelease(_context);
_context=NULL;
}
_context=context;
CGContextRetain(_context);
}
//色の指定(2)
-
(void)setColor_r:(int)r g:(int)g b:(int)b {
CGContextSetRGBFillColor(
_context,r/255.0f,g/255.0f,b/255.0f,1.0f);
CGContextSetRGBStrokeColor(
_context,r/255.0f,g/255.0f,b/255.0f,1.0f);
} -
(void)drawRect:(CGRect)rect {
// contextを取得
CGContextRef context = UIGraphicsGetCurrentContext();// 残っていた痕跡をクリア
CGContextClearRect(context, rect);// 背景色が必要ならここで設定
UIColor * _boardColor = [UIColor whiteColor];[self changeFillColorTo:(_boardColor) inContext:context];
[self changeStrokeColorTo:(_boardColor) inContext:context];[self drawRect:rect inContent:context];
// 直線の端のスタイル。ここは四角いが、円形になるも可能
CGContextSetLineCap(context, kCGLineCapSquare);
// 直線の幅を設定
CGContextSetLineWidth(context, 1.0);// TODO: 具体的な描くコード
}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/30 06:39