0
在我的主視圖中,我有一個用戶定義的類drawSquare,它是UIImageView的子類。在drawSquare.m我具有以下所示的正常的drawRect方法:如何在我的主視圖中的UIImageView上繪製形狀?無效的上下文錯誤?
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context,[UIColor redColor].CGColor);
redSquare = CGRectMake(2,2,30,34);
CGContextAddRect(context, redSquare);
CGContextStrokePath(context);
}
以我主視圖控制器我有一個名爲word1Area類型drawSquare作爲一個IBOutlet的對象。 在我的主視圖控制器我viewDidLoad方法我有臺詞:
[self.view addSubview:word1Area];
[word1Area drawRect:word1Area.frame];
我得到一個「無效的情況下」運行時錯誤。我嘗試過調用drawRect方法的其他變體,但不斷得到相同的錯誤。謝謝你的幫助。
你見過這個答案http://stackoverflow.com/questions/13153223/how-to-crop-the-image-using-uibezierpath/15353848#15353848 –