相关疑难解决方法(0)

如何使UILabel显示轮廓文字?

我想要的只是在我的白色UILabel文本周围的一个像素黑色边框.

我使用下面的代码完成了UILabel的子类化,我从几个相关的在线示例中笨拙地拼凑而成.并且它工作但它非常非常慢(除了在模拟器上)并且我无法让它垂直居中文本(因此我暂时硬编码了最后一行的y值).哈啊!

void ShowStringCentered(CGContextRef gc, float x, float y, const char *str) {
    CGContextSetTextDrawingMode(gc, kCGTextInvisible);
    CGContextShowTextAtPoint(gc, 0, 0, str, strlen(str));
    CGPoint pt = CGContextGetTextPosition(gc);

    CGContextSetTextDrawingMode(gc, kCGTextFillStroke);

    CGContextShowTextAtPoint(gc, x - pt.x / 2, y, str, strlen(str));
}


- (void)drawRect:(CGRect)rect{

    CGContextRef theContext = UIGraphicsGetCurrentContext();
    CGRect viewBounds = self.bounds;

    CGContextTranslateCTM(theContext, 0, viewBounds.size.height);
    CGContextScaleCTM(theContext, 1, -1);

    CGContextSelectFont (theContext, "Helvetica", viewBounds.size.height,  kCGEncodingMacRoman);

    CGContextSetRGBFillColor (theContext, 1, 1, 1, 1);
    CGContextSetRGBStrokeColor (theContext, 0, 0, 0, 1);
    CGContextSetLineWidth(theContext, 1.0);

    ShowStringCentered(theContext, rect.size.width / 2.0, 12, [[self text] cStringUsingEncoding:NSASCIIStringEncoding]);
} …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch core-graphics objective-c ios

102
推荐指数
7
解决办法
6万
查看次数

如何从UILabel创建图像?

我目前正在iphone上开发一个简单的Photoshop应用程序.当我想展平我的图层时,标签处于良好的位置,但字体大小不好.这是我的代码扁平化:

UIGraphicsBeginImageContext(CGSizeMake(widthDocument,widthDocument));

for (UILabel *label in arrayLabel) {
    [label drawTextInRect:label.frame];
}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

iphone objective-c flatten uiimage uilabel

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

如何通过SKEffectNode在精灵周围创建一个光晕

我有一个SKSpriteNode我希望在它的边缘有蓝色光晕以突出显示目的.我猜我需要让我的精灵成为a的孩子,SKEffectNode然后创建/应用某种过滤器.

更新:我已经使用所选答案的方法调查了这一点,并发现SKEffectNode即使你已经设置为shouldRasterize"无过滤器"定义,它也会有相当大的性能.我的结论是,如果你的游戏一次需要10个以上的移动物体,SKEffectNode即使是光栅化也不会涉及到它们.

我的解决方案可能涉及预渲染的发光图像/动画,因为SKEffectNode不会根据我的要求削减它.

如果有人对我失踪的任何事情有所了解,我会很感激你所知道的一切!

我接受了答案,因为它确实实现了我的要求,但是想要将这些笔记添加到任何想要走这条路线的人,这样你就可以了解使用中的一些问题SKEffectNode.

iphone ios sprite-kit skeffectnode

20
推荐指数
2
解决办法
2万
查看次数

SKLabelNode + NSMutableAttributedString = 无阴影

    let paragraph = NSMutableParagraphStyle()
    paragraph.alignment = NSTextAlignment.right
    paragraph.tailIndent = -3
    let shadow = NSShadow()
    shadow.shadowBlurRadius = 5
    shadow.shadowColor = UIColor.gray
    shadow.shadowOffset = CGSize(width: 2, height: -2)
    let text = NSMutableAttributedString(string: "MY LABEL", attributes:
   [NSShadowAttributeName : shadow,
    NSStrokeColorAttributeName : UIColor.black,
    NSStrokeWidthAttributeName : -3,
    NSForegroundColorAttributeName: UIColor.white,
    NSFontAttributeName : UIFont(name: "MyFont", size: 24) as Any,
    NSParagraphStyleAttributeName : paragraph])

    let node = SKLabelNode()
    addChild(node)
    node.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)

它有效,但没有阴影。我可以使用相同的NSMutableAttributedString上著名的ASAttributedLabel和它的作品不错,有一个影子,但我想使用SKLabelNode,以实现更好的性能IOS11ASAttributedLabel可能会滞后于动态场景:(

nsattributedstring nsmutableattributedstring sprite-kit sklabelnode swift

6
推荐指数
0
解决办法
375
查看次数