2013-11-23 57 views
0

我需要PaintCode片段融入了XCode,但到目前爲止,我沒有看到結果模擬器,這裏是一個長方形的片段:如何PaintCode片段融入了XCode(iOS 6中)

// Rounded Rectangle Drawing 
UIBezierPath *roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(45.5, 89.5, 232, 273) cornerRadius:3]; 
[[UIColor whiteColor] setFill]; 
[roundedRectanglePath fill]; 
[[UIColor blackColor] setStroke]; 
[roundedRectanglePath setLineWidth: 10]; 
[roundedRectanglePath stroke]; 

我在實現文件中使用的空隙功能:

- (void) drawRect: (CGRect)rect 
{ 
    // snippet goes here 
} 
+0

這是在一些UIView子類中完成的嗎?是屏幕視圖層次結構的視圖部分嗎? –

+0

不在子類中,在視圖控制器中,但我嘗試了子類,但仍然無效。 –

+0

'drawRect:'在不在視圖控制器中的視圖中工作。 –

回答

1

的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

現在,所有這一切說,你的突出顯示子視圖大概覆蓋了你想突出顯示的按鈕;所以,即使你可以看到按鈕,它可能不會,除非你對這種觀點fancyView.userInteractionEnabled = NO;

+0

謝謝@NSBum現在我看到了矩形,但是我看不到我的應用程序的其餘部分,即想法是在頂部繪製矩形。我嘗試了initWithFrame:CGRectMake(45.5,89.5,232,273),但這只是給我一個黑色的矩形。 –

+0

也許你可以描述或說明你想如何看待視圖。 – FluffulousChimp

+0

我希望視圖具有透明填充(clearColor I suppose)矩形,例如在一個預先存在的按鈕上(一個用Interface Builder製作),基本上只是爲了突出它。 –

0

禁用用戶交互,如果你只想做PaintCode片段的快速顯示嘗試

https://github.com/kaishin/Verbena

響應觸摸事件

內聯核心圖形渲染到UIImage - 用於PaintCode