UITableViewCell Circle Bullet Point

Ben*_*nck 3 geometry objective-c uitableview ios cgrect

我一直在努力实现像iOS日历应用程序中的彩色圆点子弹点.

选择视图

我想在textLabel前面放置带圆圈的单元格,如上图所示.

选定的视图

而且我也希望在detailTextLabel前面有相应的圆圈,如上图所示.

我试图用一个框架内的图像来做这个,但它总是太大了.此外,日历应用程序中的圆圈似乎不在单元格的imageView中.

我也尝试用另一个问题找到的代码绘制一个圆圈.这段代码对我不起作用.这是我的XYZCircleView.m文件中的代码:

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context= UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetAlpha(context, 0.5);
    CGContextFillEllipseInRect(context, CGRectMake(0,0,self.frame.size.width,self.frame.size.height));

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    //CGContextStrokeEllipseInRect(context, CGRectMake(0,0,self.frame.size.width,self.frame.size.height));
    CGContextStrokeEllipseInRect(context, CGRectMake(1, 1, self.frame.size.width - 2,    self.frame.size.height - 2));
}
Run Code Online (Sandbox Code Playgroud)

在我的内心cellForRow...:

CGRect positionFrame = CGRectMake(10,10,10,10);
XYZCircleView *circleView = [[XYZCircleView alloc] initWithFrame:positionFrame];
[cell.contentView addSubview:circleView];
Run Code Online (Sandbox Code Playgroud)

如何才能做到这一点?

谢谢

rma*_*ddy 5

使用项目符号字符并使用属性字符串,以便设置项目符号的颜色.

像这样的东西:

NSString *text = @"• Calendar";
NSDictionary *attributes = @{ NSFontAttributeName : [UIFont systemFontOfSize:15] };
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes];
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 1)]; // color the bullet
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(1, attrStr.length - 1)]; // color the rest

cell.text.attributedText = attrStr;
Run Code Online (Sandbox Code Playgroud)

您可能需要根据需要使用不同的字体.