日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

如何定制Core Plot主題

系統 1850 0

CorePlot主題是一個CPTheme子類。CPTheme提供了一系列方法,你可以覆蓋其中3個方法 從而實現自定義的主題:

1、 -( void )applyThemeToBackground:( CPGraph *)graph;

通過傳遞進來的 CPGraph參數,設置背景CPGraph

2、 -( void )applyThemeToPlotArea:( CPPlotAreaFrame *)plotAreaFrame;

通過傳遞進來的 CPPlotArea參數,設置PlotArea風格

3、 -( void )applyThemeToAxisSet:( CPAxisSet *)axisSet;

通過傳遞進來的 CPAxisSet參數,設置坐標系風格

下面是一個 CPTheme子類的例子:

一、 .h文件

.h文件很簡單,申明父類為CPTheme:

#import <Foundation/Foundation.h>

#import <CorePlot/CorePlot.h>

@interface MyCPTheme : CPXYTheme {

}

@end

二、 .m文件

1、首先我們來為背景設置一個自定義顏色漸變:

-( void )applyThemeToBackground:( CPXYGraph *)graph

{

// 終點色: 20 %的灰度

CPColor *endColor = [ CPColor colorWithGenericGray : 0.2f ];

// 創建一個漸變區:起點、終點都是 0.2 的灰度

CPGradient *graphGradient = [ CPGradient gradientWithBeginningColor :endColor endingColor :endColor];

// 設置中間漸變色 1 ,位置在 30 %處,顏色為 3 0 %的灰

graphGradient = [graphGradient addColorStop :[ CPColor colorWithGenericGray : 0.3f ] atPosition : 0.3f ];

// 設置中間漸變色 2 ,位置在 50 %處,顏色為 5 0 %的灰

graphGradient = [graphGradient addColorStop :[ CPColor colorWithGenericGray : 0.5f ] atPosition : 0.5f ];

// 設置中間漸變色 3 ,位置在 60 %處,顏色為 3 0 %的灰

graphGradient = [graphGradient addColorStop :[ CPColor colorWithGenericGray : 0.3f ] atPosition : 0.6f ];

// 漸變角度:垂直 90 度(逆時針)

graphGradient. angle = 90.0f ;

// 漸變填充

graph. fill = [ CPFill fillWithGradient :graphGradient];

}

2、在坐標軸上畫上網格線:

// Y 軸上添加平行線

-( void )applyThemeToAxisSet:( CPXYAxisSet *)axisSet {

// 設置網格線線型

CPLineStyle *majorGridLineStyle = [ CPLineStyle lineStyle ];

majorGridLineStyle. lineWidth = 1.0f ;

majorGridLineStyle. lineColor = [ CPColor lightGrayColor ];

CPXYAxis *axis=axisSet. yAxis ;

// 軸標簽方向: CPSignNone -無,同 CPSignNegative CPSignPositive -反向 , y 軸的右邊, CPSignNegative -正向,在 y 軸的左邊

axis. tickDirection = CPSignNegative ;

// 設置平行線,默認是以大刻度線為平行線位置

axis. majorGridLineStyle = majorGridLineStyle ;

// 如果 labelingPolicy 設置為 CPAxisLabelingPolicyNone majorGridLineStyle 將不起作用

//axis.labelingPolicy = CPAxisLabelingPolicyNone ;

}

3、設置繪圖區

下面的代碼在繪圖區( PlotArea)填充一個灰色漸變。注意由于繪圖區(PlotArea)位于背景圖(Graph)的上層(參考 Core Plot 框架的類層次圖 ),因此對于繪圖區所做的設置會覆蓋對 Graph 所做的設置,除非你故意在 Graph 4 邊留白,否則看不到背景圖的設置。

-( void )applyThemeToPlotArea:( CPPlotAreaFrame *)plotAreaFrame

{

// 創建一個 20 -50 %的灰色漸變區,用于設置繪圖區。

CPGradient *gradient = [ CPGradient gradientWithBeginningColor :[ CPColor colorWithGenericGray : 0.2f ] endingColor :[ CPColor colorWithGenericGray : 0.7f ]];

gradient. angle = 45.0f ;

// 漸變填充

plotAreaFrame. fill = [ CPFill fillWithGradient :gradient];

}

三、應用主題

很簡單,將 CPTheme替換成我們自己的主題,并應用到CPGraph:

#import "MyCPTheme.h"

??

CPTheme *theme=[[ MyCPTheme alloc ] init ];

[ graph applyTheme :theme];

來看看效果:

如何定制Core Plot主題

如何定制Core Plot主題

如何定制Core Plot主題

如何定制Core Plot主題


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 随州市| 林芝县| 佛冈县| 天柱县| 沂水县| 龙山县| 通州市| 宁德市| 鹤庆县| 共和县| 城口县| 溧水县| 玛曲县| 河池市| 临猗县| 大关县| 邹城市| 鹤壁市| 富蕴县| 开原市| 西贡区| 太谷县| 邛崃市| 洪雅县| 土默特左旗| 广灵县| 灌阳县| 乌苏市| 康保县| 兰溪市| 师宗县| 周至县| 黄陵县| 淅川县| 大田县| 准格尔旗| 蓬莱市| 乌兰察布市| 山西省| 香港 | 社会|