我一直在尝试像在 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));
}
在我的 cellForRow...
中:
CGRect positionFrame = CGRectMake(10,10,10,10);
XYZCircleView *circleView = [[XYZCircleView alloc] initWithFrame:positionFrame];
[cell.contentView addSubview:circleView];
如何做到这一点?
谢谢
最佳答案
使用项目符号字符并使用属性字符串,以便您可以设置项目符号的颜色。
像这样:
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;
您可能需要根据需要使用不同的字体或颜色。
关于ios - UITableViewCell 圆圈项目符号点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25004897/