iphone obj-c error:使用Core Plot时分配给只读属性

时间:2021-09-02 20:06:04

So I'm trying to create some graphs using Core Plot, but for the following lines of code:

所以我试图使用Core Plot创建一些图形,但是对于以下代码行:

CPTLineStyle *lineStyle = [[[CPTLineStyle lineStyle] alloc] init];
[lineStyle lineColor] = [CPTColor blackColor];
[lineStyle lineWidth] = 2.0f;

I'm getting an "Assignment to readonly property" error (for the second and thir lines), when clearly lineColor and lineWidth are assignable properties. I've been racking my brain about this for some time now, so hopefully someone knows what the issue might be.

当明确lineColor和lineWidth是可分配的属性时,我得到一个“Asson to readonly property”错误(对于第二行和第二行)。我一直在讨论这个问题,所以希望有人知道问题可能是什么。

2 个解决方案

#1


4  

You need to use CPTMutableLineStyle, all of the properties in CPTLineStyle are read-only and can only be set when initializing the LineStyle.
And your syntax for setting the properties is wrong.

您需要使用CPTMutableLineStyle,CPTLineStyle中的所有属性都是只读的,只能在初始化LineStyle时设置。您设置属性的语法是错误的。

#2


3  

This has nothing to do with Core Plot. Your syntax is wrong. Either:

这与Core Plot无关。你的语法错了。或者:

[lineStyle setLineColor:[CPTColor blackColor]];
[lineStyle setLineWidth:2.0f];

or:

lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;

#1


4  

You need to use CPTMutableLineStyle, all of the properties in CPTLineStyle are read-only and can only be set when initializing the LineStyle.
And your syntax for setting the properties is wrong.

您需要使用CPTMutableLineStyle,CPTLineStyle中的所有属性都是只读的,只能在初始化LineStyle时设置。您设置属性的语法是错误的。

#2


3  

This has nothing to do with Core Plot. Your syntax is wrong. Either:

这与Core Plot无关。你的语法错了。或者:

[lineStyle setLineColor:[CPTColor blackColor]];
[lineStyle setLineWidth:2.0f];

or:

lineStyle.lineColor = [CPTColor blackColor];
lineStyle.lineWidth = 2.0f;