2012年1月23日月曜日

UIViewをサブクラス化しないで blocksでdrawRect: を書けるライブラリ - UIViewDrawRectBlock

これはいいかも。こんな感じで書ける(紹介ページより引用)
- (void)viewDidLoad {
    __weak MyViewController *weakRef = self;
    [self.view addSubview:[UIView viewWithFrame:CGRectMake(20, 40, 60, 60)
                                  drawRectBlock:^(CGRect rect) {
                                      CGContextRef c = UIGraphicsGetCurrentContext();
                                      CGContextSetFillColorWithColor(c, weakRef.fillColor.CGColor);
                                      CGContextFillRect(c, rect);
                                  }]];
}
ちょっとした視覚表現をサブクラスファイルを作らずにアドホックにできるのがいい。


0 件のコメント:

コメントを投稿