LoginSignup
1
0

More than 5 years have passed since last update.

cellの上下にラインを引いて綺麗に見せるスニペット。

Last updated at Posted at 2012-12-26

記念投稿なので大したあれじゃないですが。
もちろんcellじゃなくても。

CustomCell.m
- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];

    CGFloat width = self.bounds.size.width;
    CGFloat height = self.bounds.size.height;    
    CGFloat lineWidth = 2.0;

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextMoveToPoint(context, 0.0, 0.0);
    CGContextAddLineToPoint(context, width, 0.0);

    UIColor *topColor = [UIColor colorWithWhite:1.0 alpha:1.0];
    CGContextSetStrokeColorWithColor(context, [topColor CGColor]);

    CGContextSetLineWidth(context, lineWidth);
    CGContextStrokePath(context);

    CGContextMoveToPoint(context, 0.0, height);
    CGContextAddLineToPoint(context, width, height);

    UIColor *bottomColor = [UIColor colorWithWhite:0.85 alpha:1.0];
    CGContextSetStrokeColorWithColor(context, [bottomColor CGColor]);

    CGContextStrokePath(context);
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0