Draw a Custom cell for tableview ( uitableview ) , with changed colors and separator color and width

匿名 (未验证) 提交于 2019-12-03 01:56:01

问题:

I want to draw the background of a UITableViewCell which has a grouped style. The problem with me is I am not able to call the -(void)drawRect:(CGRect)rect or I think it should be called programmatically...

I have taken code from following link .

How to customize the background/border colors of a grouped table view cell?

// //  CustomCellBackgroundView.h // //  Created by Mike Akers on 11/21/08. //  Copyright 2008 __MyCompanyName__. All rights reserved. //  #import   typedef enum  {     CustomCellBackgroundViewPositionTop,      CustomCellBackgroundViewPositionMiddle,      CustomCellBackgroundViewPositionBottom,     CustomCellBackgroundViewPositionSingle } CustomCellBackgroundViewPosition;  @interface CustomCellBackgroundView : UIView {     UIColor *borderColor;     UIColor *fillColor;     CustomCellBackgroundViewPosition position; }      @property(nonatomic, retain) UIColor *borderColor, *fillColor;     @property(nonatomic) CustomCellBackgroundViewPosition position; @end  // //  CustomCellBackgroundView.m // //  Created by Mike Akers on 11/21/08. //  Copyright 2008 __MyCompanyName__. All rights reserved. //  #import "CustomCellBackgroundView.h"  static void addRoundedRectToPath(CGContextRef context, CGRect rect,                                  float ovalWidth,float     ovalHeight);  @implementation CustomCellBackgroundView @synthesize borderColor, fillColor, position;  - (BOOL) isOpaque {     return NO; }  - (id)initWithFrame:(CGRect)frame {     if (self = [super initWithFrame:frame]) {         // Initialization code     }     return self; }  - (void)drawRect:(CGRect)rect {     // Drawing code     CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(c, [fillColor CGColor]); CGContextSetStrokeColorWithColor(c, [borderColor CGColor]); CGContextSetLineWidth(c, 2.0);  if (position == CustomCellBackgroundViewPositionTop) {      CGFloat minx = CGRectGetMinX(rect) , midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ;     CGFloat miny = CGRectGetMinY(rect) , maxy = CGRectGetMaxY(rect) ;     minx = minx + 1;     miny = miny + 1;      maxx = maxx - 1;     maxy = maxy ;      CGContextMoveToPoint(c, minx, maxy);     CGContextAddArcToPoint(c, minx, miny, midx, miny, ROUND_SIZE);     CGContextAddArcToPoint(c, maxx, miny, maxx, maxy, ROUND_SIZE);     CGContextAddLineToPoint(c, maxx, maxy);      // Close the path     CGContextClosePath(c);     // Fill & stroke the path     CGContextDrawPath(c, kCGPathFillStroke);                     return; }  else if (position == CustomCellBackgroundViewPositionBottom) {      CGFloat minx = CGRectGetMinX(        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!