2
msg backgroundをtableviewcellに書きますが、スクロールすると表示が異なります。 "コンテキスト"のようにいくつかの状態を格納するようだ。 コードは矢印付きの丸い矩形を描画します。矢印のサイズは固定する必要がありますが、実際には時々スクロールして変更されます。CoreGraphicsと同じコードが異なる
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;
CGFloat arrowHeight = 10;
CGFloat arrowWidth = 5;
CGFloat arrowOffset = 5;
CGFloat radius = 5;
CGFloat shadowHeight = 2;
CGFloat shadowOffset = 4;
CGColorRef shadowColor = [UIColor colorWithRed:0.2f
green:0.2f
blue:0.2f
alpha:0.5f].CGColor;
CGColorRef color;
color = [UIColor whiteColor].CGColor;
CGContextSaveGState(context);
CGContextMoveToPoint(context, width/2, 0);
CGContextAddArcToPoint(context, width - arrowWidth, 0, width - arrowWidth, height - shadowOffset, radius);
CGContextAddLineToPoint(context, width - arrowWidth, arrowOffset);
CGContextAddLineToPoint(context, width, arrowOffset + arrowHeight/2);
CGContextAddLineToPoint(context, width - arrowWidth, arrowOffset + arrowHeight);
CGContextAddArcToPoint(context, width - arrowWidth, height - shadowOffset, shadowOffset, height - shadowOffset, radius);
CGContextAddArcToPoint(context, shadowOffset, height - shadowOffset, shadowOffset, 0, radius);
CGContextAddArcToPoint(context, shadowOffset, 0, width, 0, radius);
CGContextSetShadowWithColor(context, CGSizeMake(0, shadowHeight), 3.0, shadowColor);
CGContextSetFillColorWithColor(context, color);
CGContextFillPath(context);
CGContextRestoreGState(context);
}
このような効果:
この 'drawRect'は、あなたがテーブルビューのセルに追加したUIViewサブクラスにありますか?どのようにビューを追加しましたか?どの自動サイズ調整用マスクにはありますか? – jrturton
はい、私はテーブルビューのセルのcontentViewにビューを追加します。自動サイズ設定マスクを設定しないでください。UIViewAutoresizingNoneだと思います。 –