600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 单数复数php单元格背景颜色 如何自定义分组表视图单元格的背景/边框颜色?...

单数复数php单元格背景颜色 如何自定义分组表视图单元格的背景/边框颜色?...

时间:2021-01-20 19:50:06

相关推荐

单数复数php单元格背景颜色 如何自定义分组表视图单元格的背景/边框颜色?...

在iPhone OS 3.0及更高版本中UITableViewCell现在有一个backgroundColor属性,使这非常容易(特别是与[UIColor colorWithPatternImage:]初始化程序结合使用)。但我会在这里为需要它的人留下2.0版的答案......

它比实际应该更难。以下是我必须这样做时的方法:

您需要将UITableViewCell的backgroundView属性设置为自定义UIView,以适当的颜色绘制边框和背景本身。此视图需要能够以4种不同的模式绘制边框,在一个部分中的第一个单元格的顶部倒圆,在截面的最后一个单元格的底部倒圆,在截面中间的单元格没有圆角,并在包含一个单元格的部分的所有4个角上舍入。

不幸的是我无法弄清楚如何自动设置这个模式,所以我不得不在UITableViewDataSource的-cellForRowAtIndexPath方法中设置它。

这是一个真正的PITA,但我已经向Apple工程师证实,这是目前唯一的方法。

更新这是自定义bg视图的代码。有一个绘图错误,使圆角看起来有点滑稽,但我有机会修复它之前我们转移到不同的设计并废弃自定义背景。这仍然可能对你非常有帮助:CustomCellBackgroundView.hCreatedbyMikeAkerson11/21/08.//Copyright__MyCompanyName__.Allrightsreserved.//#importtypedefenum{

CustomCellBackgroundViewPositionTop,

CustomCellBackgroundViewPositionMiddle,

CustomCellBackgroundViewPositionBottom,

CustomCellBackgroundViewPositionSingle}CustomCellBackgroundViewPosition;@interfaceCustomCellBackgroundView:UIView{

UIColor*borderColor;

UIColor*fillColor;

CustomCellBackgroundViewPositionposition;}

@property(nonatomic,retain)UIColor*borderColor,*fillColor;

@property(nonatomic)CustomCellBackgroundViewPositionposition;@endCustomCellBackgroundView.mCreatedbyMikeAkerson11/21/08.//Copyright__MyCompanyName__.Allrightsreserved.//#import"CustomCellBackgroundView.h"staticvoidaddRoundedRectToPath(CGContextRefcontext,CGRectrect,

floatovalWidth,floatovalHeight);@implementationCustomCellBackgroundView@synthesizeborderColor,fillColor,position;-(BOOL)isOpaque{

returnNO;}-(id)initWithFrame:(CGRect)frame{

if(self=[superinitWithFrame:frame]){

//Initializationcode

}

returnself;}-(void)drawRect:(CGRect)rect{

//Drawingcode

CGContextRefc=UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(c,[fillColorCGColor]);

CGContextSetStrokeColorWithColor(c,[borderColorCGColor]);

if(position==CustomCellBackgroundViewPositionTop){

CGContextFillRect(c,CGRectMake(0.0f,rect.size.height-10.0f,rect.size.width,10.0f));

CGContextBeginPath(c);

CGContextMoveToPoint(c,0.0f,rect.size.height-10.0f);

CGContextAddLineToPoint(c,0.0f,rect.size.height);

CGContextAddLineToPoint(c,rect.size.width,rect.size.height);

CGContextAddLineToPoint(c,rect.size.width,rect.size.height-10.0f);

CGContextStrokePath(c);

CGContextClipToRect(c,CGRectMake(0.0f,0.0f,rect.size.width,rect.size.height-10.0f));

}elseif(position==CustomCellBackgroundViewPositionBottom){

CGContextFillRect(c,CGRectMake(0.0f,0.0f,rect.size.width,10.0f));

CGContextBeginPath(c);

CGContextMoveToPoint(c,0.0f,10.0f);

CGContextAddLineToPoint(c,0.0f,0.0f);

CGContextStrokePath(c);

CGContextBeginPath(c);

CGContextMoveToPoint(c,rect.size.width,0.0f);

CGContextAddLineToPoint(c,rect.size.width,10.0f);

CGContextStrokePath(c);

CGContextClipToRect(c,CGRectMake(0.0f,10.0f,rect.size.width,rect.size.height));

}elseif(position==CustomCellBackgroundViewPositionMiddle){

CGContextFillRect(c,rect);

CGContextBeginPath(c);

CGContextMoveToPoint(c,0.0f,0.0f);

CGContextAddLineToPoint(c,0.0f,rect.size.height);

CGContextAddLineToPoint(c,rect.size.width,rect.size.height);

CGContextAddLineToPoint(c,rect.size.width,0.0f);

CGContextStrokePath(c);

return;//noneedtobotherdrawingroundedcorners,sowereturn

}

//Atthispointthecliprectissettoonlydrawtheappropriate

//corners,sowefillandstrokearoundedrecttakingtheentirerect

CGContextBeginPath(c);

addRoundedRectToPath(c,rect,10.0f,10.0f);

CGContextFillPath(c);

CGContextSetLineWidth(c,1);

CGContextBeginPath(c);

addRoundedRectToPath(c,rect,10.0f,10.0f);

CGContextStrokePath(c);}-(void)dealloc{

[borderColorrelease];

[fillColorrelease];

[superdealloc];}@endstaticvoidaddRoundedRectToPath(CGContextRefcontext,CGRectrect,

floatovalWidth,floatovalHeight){

floatfw,fh;

if(ovalWidth==0||ovalHeight==0){//1

CGContextAddRect(context,rect);

return;

}

CGContextSaveGState(context);//2

CGContextTranslateCTM(context,CGRectGetMinX(rect),//3

CGRectGetMinY(rect));

CGContextScaleCTM(context,ovalWidth,ovalHeight);//4

fw=CGRectGetWidth(rect)/ovalWidth;//5

fh=CGRectGetHeight(rect)/ovalHeight;//6

CGContextMoveToPoint(context,fw,fh/2);//7

CGContextAddArcToPoint(context,fw,fh,fw/2,fh,1);//8

CGContextAddArcToPoint(context,0,fh,0,fh/2,1);//9

CGContextAddArcToPoint(context,0,0,fw/2,0,1);//10

CGContextAddArcToPoint(context,fw,0,fw,fh/2,1);//11

CGContextClosePath(context);//12

CGContextRestoreGState(context);//13}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。