Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell圆形项目符号点_Ios_Objective C_Uitableview_Geometry_Cgrect - Fatal编程技术网

Ios UITableViewCell圆形项目符号点

Ios UITableViewCell圆形项目符号点,ios,objective-c,uitableview,geometry,cgrect,Ios,Objective C,Uitableview,Geometry,Cgrect,我一直在尝试在iOS日历应用程序中实现彩色圆圈项目符号 我想要在文本标签前面有圆圈的单元格,如上图所示 我还想在detailTextLabel前面画一个对应的圆圈,如上图所示 我试着在一个框架内制作一个图像,但它总是太大了。另外,日历应用程序中的圆圈似乎不在单元格的imageView中 我还试着用从另一个问题中找到的一些代码画一个圆圈。但是这个代码对我不起作用。下面是我的XYZCircleView.m文件中的代码: - (void)drawRect:(CGRect)rect { //

我一直在尝试在iOS日历应用程序中实现彩色圆圈项目符号

我想要在文本标签前面有圆圈的单元格,如上图所示

我还想在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));
}
在我的
手机里…

CGRect positionFrame = CGRectMake(10,10,10,10);
XYZCircleView *circleView = [[XYZCircleView alloc] initWithFrame:positionFrame];
[cell.contentView addSubview:circleView];
如何做到这一点


感谢您,只需尝试将方形视图作为子视图添加到单元格中,并设置其图层的
cornerRadius
属性,使其成为圆形。

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

大概是这样的:

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;

您可能需要根据需要使用不同的字体或颜色。

对于第二个单元格,如果颜色和日历名称需要显示在单元格的
detailTextLabel
中,这将如何工作?也许您需要一个表视图单元格子类,您可以根据需要布局自己的视图七,尽管我在许多方面使用了rounak的解决方案我更喜欢这种解决方案。在我看来,更优雅。和我第一次碰到的完全一样,谢谢!这是一个非常简单的解决方案。
NSFontAttributeName
部分是否确定项目符号大小?或者如何使其变大?字体适用于整个字符串。尝试不同的项目符号字符,例如∙ 或•或・ 或● 或⬤ 或⚫︎.我想我应该声明,你可以对字符串的不同部分应用两种不同的字体,就像颜色一样。但是如果你需要的话,使用更大的子弹会更容易。