Переменные bounds, width и height в настоящее время являются локальными переменными.Я не могу получить к ним доступ из других классов или даже получить доступ к ним из другого метода.
Как я могу сделать эти переменные доступными для всего экземпляра?Я попытался поместить их в файл .h и переименовать их в CGFloats безрезультатно.
#import "TicTacToeBoard.h"
@implementation TicTacToeBoard
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGRect bounds = [self bounds];
float width = bounds.size.width;
float height = bounds.size.height;
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(ctx, 0.3, 0.3, 0.3, 1);
CGContextSetLineWidth(ctx, 5);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextMoveToPoint(ctx, width/3, height * 0.95);
CGContextAddLineToPoint(ctx, width/3, height * 0.05);
CGContextStrokePath(ctx);
}
@end