的PaintCode產生需要被包裹在一個UIView
子類的drawRect:
方法的代碼。
您還應該:
導入在UIViewController
子類的頭文件,你似乎與合作,即#import "OnScreenGraphics.h"
創建類的實例,例如
// add a subview to fill the entire view; your requirements
// may be different, of course
OnScreenGraphics *fancyView = [[OnScreenGraphics alloc] initWithFrame:self.view.bounds];
[[self view] addSubview:fancyView];
編輯2013年11月24日07-33-25
#import <UIKit/UIKit.h>
@interface OnScreenGraphics : UIView
@end
#import "OnScreenGraphics.h"
@implementation OnScreenGraphics
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if(!self) return nil;
self.backgroundColor = [UIColor clearColor];
return self;
}
- (void)drawRect:(CGRect)rect{
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(45.5, 89.5, 232, 273) cornerRadius:3];
[[UIColor clearColor] setFill];
[roundedRectanglePath fill];
[[UIColor blackColor] setStroke];
[roundedRectanglePath setLineWidth: 10];
[roundedRectanglePath stroke];
}
@end
And in your view controller implementation:
@implementation AKDMoreDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
OnScreenGraphics *fancyView = [[OnScreenGraphics alloc] initWithFrame:self.view.bounds];
[[self view] addSubview:fancyView];
}
// etc.
@end
當我在一個測試項目執行此,我看到:
![rectangle-image](https://i.stack.imgur.com/sDJlI.png)
現在,所有這一切說,你的突出顯示子視圖大概覆蓋了你想突出顯示的按鈕;所以,即使你可以看到按鈕,它可能不會,除非你對這種觀點fancyView.userInteractionEnabled = NO;
這是在一些UIView子類中完成的嗎?是屏幕視圖層次結構的視圖部分嗎? –
不在子類中,在視圖控制器中,但我嘗試了子類,但仍然無效。 –
'drawRect:'在不在視圖控制器中的視圖中工作。 –