小编Mos*_*bah的帖子

使用UIBezierPath绘制圆圈

我正在尝试使用UIBezierPath addArcWithCenter方法绘制一个圆圈:

UIBezierPath *bezierPath = 
  [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0., 0., 100., 100.)];

[bezierPath addArcWithCenter:center 
                      radius:0. 
                  startAngle:0 endAngle:2 * M_PI clockwise:YES];

CAShapeLayer *progressLayer = [[CAShapeLayer alloc] init];

[progressLayer setPath:bezierPath.CGPath];
[progressLayer setStrokeColor:[UIColor colorWithWhite:1. alpha:.2].CGColor];
[progressLayer setFillColor:[UIColor clearColor].CGColor];
[progressLayer setLineWidth:.3 * self.bounds.size.width];
[progressLayer setStrokeStart:_volumeValue/100.];
[progressLayer setStrokeEnd:volume/100.]; // between 0 and 100

[_circleView.layer addSublayer:progressLayer];
Run Code Online (Sandbox Code Playgroud)

但我得到的是以下内容:

在此输入图像描述

我尝试使用不同的参数,但没有运气

谢谢

更新:

如果我不解释我要做的事,我很抱歉:

*使用以下方式绘制背景圆圈:

[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0., 0., 100., 100.)]
Run Code Online (Sandbox Code Playgroud)

*我正在尝试使用两个值之间的bezierPathWithOvalInRect逐步绘制红色圆圈:_volumeValue和音量

但我无法得到一个完美的圆圈,相反,我得到了一定价值之后的水平部分.

在此输入图像描述

objective-c calayer cabasicanimation cashapelayer

13
推荐指数
1
解决办法
3万
查看次数

NSAttributedString带有图像附件和NSTextTab,文本未对齐

我正试图在左边有一个带有图像和标题的UIlabel,在右边有一个带有项目符号的描述列表,为此我正在使用NSAttributedString,如下所示:

        NSMutableParagraphStyle *pStyle = [[NSMutableParagraphStyle alloc] init];
    pStyle.tabStops =
        @[ [[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft location:tabLocation options:[NSDictionary dictionary]] ];

    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
    textAttachment.image = [UIImage imageNamed:@"test_image"];
    textAttachment.bounds = CGRectMake(0, -3, 15, 15);//resize the image
    attString = [NSAttributedString attributedStringWithAttachment:textAttachment].mutableCopy;
    [attString appendAttributedString:[[NSAttributedString alloc]
                                          initWithString:[NSString stringWithFormat:@"title\t\u2022 %@",
                                                                                    [@[ @"description1", @"description2" ]
                                                                                        componentsJoinedByString:@"\n\t\u2022 "]]
                                              attributes:@{NSParagraphStyleAttributeName : pStyle}]];
    label.attributedText = attString;
Run Code Online (Sandbox Code Playgroud)

我希望右边的列表保持对齐但事实并非如此,这是我得到的结果:

在此输入图像描述

我期望列表是这样对齐的: 在此输入图像描述

nstextattachment core-text ios nstexttab nsparagraphstyle

8
推荐指数
1
解决办法
2037
查看次数