Iphone 用于索引/计数的TableView椭圆形按钮

Iphone 用于索引/计数的TableView椭圆形按钮,iphone,uitableview,count,indexing,Iphone,Uitableview,Count,Indexing,有人能帮我为UITableView创建一个索引/计数按钮吗 是否有一个苹果的例子,或其他教程?谢谢,Jordan您需要创建一个自定义视图,然后手动绘制椭圆和数字。最后,将该自定义视图指定为单元的附件视图。这是使用核心图形的绘图代码。这并不太棘手: 哇。。。aaa。。。好啊我有一个更简单的方法: 基本上,您正在使用QuartzCore框架制作带有圆角的UILabel—别忘了包含它。额外说明:它只适用于OS>3.0。啊,是的,cornerRadius很酷,但正如他所说,它只适用于3.0。Ben,我想

有人能帮我为UITableView创建一个索引/计数按钮吗


是否有一个苹果的例子,或其他教程?谢谢,Jordan

您需要创建一个自定义视图,然后手动绘制椭圆和数字。最后,将该自定义视图指定为单元的附件视图。这是使用核心图形的绘图代码。这并不太棘手:
哇。。。aaa。。。好啊我有一个更简单的方法:


基本上,您正在使用QuartzCore框架制作带有圆角的UILabel—别忘了包含它。额外说明:它只适用于OS>3.0。

啊,是的,cornerRadius很酷,但正如他所说,它只适用于3.0。Ben,我想不出有什么理由让越狱者选择继续使用iPhone OS v2.2.1或之前的版本。你能? CGRect bounds = self.bounds; CGContextRef context = UIGraphicsGetCurrentContext(); float radius = bounds.size.height / 2.0; NSString *countString = [NSString stringWithFormat: @"%d", _count];

if (_count < 100) bounds = CGRectMake(5, 0, bounds.size.width - 10, bounds.size.height);

CGContextClearRect(context, bounds);

CGContextSetFillColorWithColor(context, _color.CGColor);
CGContextBeginPath(context);
CGContextAddArc(context, radius + bounds.origin.x, radius, radius, M_PI / 2 , 3 * M_PI / 2, NO);
CGContextAddArc(context, (bounds.size.width + bounds.origin.x) - radius, radius, radius, 3 * M_PI / 2, M_PI / 2, NO);
CGContextClosePath(context);
CGContextFillPath(context);

[[UIColor whiteColor] set];

UIFont                  *font = [UIFont boldSystemFontOfSize: 14];
CGSize                  numberSize = [countString sizeWithFont: font];

bounds.origin.x += (bounds.size.width - numberSize.width) / 2;

[countString drawInRect: bounds withFont: font];
#import <QuartzCore/QuartzCore.h>


.....

UILabel *label = [[UILabel alloc] initWithFrame: 
        CGRectMake(cell.contentView.frame.size.width - 50, 0, 35, 35)];
label.layer.cornerRadius = 5;
label.backgroundColor = [UIColor blueColor]; //feel free to be creative
label.clipToBounds = YES;
label.text = @"7"; //Your text here

[cell.contentView addSubview: label];
[label release];