我试着在我的标签上勾勒出绿色的轮廓,但它不起作用.. 我的代码是
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "HoboStd", 50);
pLabel->setPosition(ccp(200,200));
pLabel->enableStroke(ccGREEN, 5.0,true);
this->addChild(pLabel);
它没有提供标签文本Hello World周围的轮廓。这里有谁可以帮助我
答案 0 :(得分:1)
我在ios7.0中修复了如何在标签上启用描边功能 标签的正常行程代码在IOS 7.0中不起作用,但它在IOS 7.0下成功运行 下面提供了启用描边的基本代码。我们需要添加一个CCLabelTTF,然后调用enableStroke函数
CCLabelTTF *label=CCLabelTTF::create("Hello", "Arial.fnt", 50);
label->setPosition(ccp(300,300));
label->enableStroke(ccGREEN, 1.0,true);
this->addChild(label);
这适用于低于7.0的IOS。但在IOS 7.0中,标签上没有任何抚摸效果。要解决问题,请按照以下步骤进行操作
在项目中找到CCImage.mm文件,找到下面编写的代码
//actually draw the text in the context
//XXX: ios7 casting
[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font
lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];
现在在此行下方添加以下代码
//New Code Start
if(pInfo->hasStroke)
{
CGContextSetTextDrawingMode(context, kCGTextStroke);
CGContextSetRGBFillColor(context, pInfo->strokeColorR, pInfo->strokeColorG, pInfo->strokeColorB,
1);
CGContextSetLineWidth(context, pInfo->strokeSize);
[str drawInRect:CGRectMake(textOriginX, textOrigingY, textWidth, textHeight) withFont:font
lineBreakMode:NSLineBreakByWordWrapping alignment:(NSTextAlignment)align];
}
//New Code End
保存CCImage.mm文件,然后再次重新运行项目。它将使用正确的颜色重绘笔划。在7.0模拟器上进行测试
答案 1 :(得分:0)
我测试了你的代码,我得到了大纲。尝试将笔划宽度减小到1.0。
pLabel->enableStroke(ccGREEN, 1.0,true);