Hi all. For a calendar widget, I am trying to replace common words with SFSymbols, to conserve space.
I’m testing it with turning “call” into a phone symbol. However, instead of getting the symbol itself in my widget, I get [object SFSymbol] or [object Image] if I use the .image property.
How do I get the symbol to render? Is this a problem with my javascript, the way I’m using SFSymbols in Scriptable, or something else? Thanks!
Here’s the function I wrote — I just pass the calendar title text to it before inserting the result as the widget line text.
function mod(title_text) {
split = title_text.split(" ");
var result_list = [];
var i;
for (i=0; i<split.length; i++) {
if (split[i].toLowerCase() == "call") {
r = SFSymbol.named("phone.arrow.up.right")
}
else {
r = split[i];
} // end else
result_list.push(r);
} // end for loop
result = result_list.join(" ");
return result
} // end mod funx
Hm. I tried that. Here’s the section of the script that calls my function:
let title_text = mod(futureEvents[i].title)
let title = widget.addText(title_text)
title.font = Font.semiboldSystemFont(titleSizeNow)
Here’s the result:
Here’s the function calling the .image property
function mod(title_text) {
split = title_text.split(" ");
var result_list = [];
var i;
for (i=0; i<split.length; i++) {
if (split[i].toLowerCase() == "call") {
r = SFSymbol.named("phone.arrow.up.right")
r = r.image
}
else {
r = split[i];
} // end else
result_list.push(r);
} // end for loop
result = result_list.join(" ");
return result
} // end mod funx
I wasn’t. Are you getting the same result? I’m wondering if I have to explicitly use SF fonts. I thought that was my default system font already though.
let sym = SFSymbol.named("tortoise")
let w = new ListWidget()
let wimg = w.addImage(sym.image)
wimg.tintColor = Color.blue()
wimg.imageSize = new Size(50, 50)
w.presentSmall()
Unfortunately, I want the symbol inline with the text rather than as an image. So easier to use an emoji instead. But now I know how to use SFSymbol if it comes up again. Thanks!
Right, that’s not really supported. Depending on your exact needs, you may be able to split up your text and insert it into a horizontal stack with an SFSymbol. If tweaked correctly, it might be possible to make it look like the image is part of the text.
I want to draw the symbol image into a DrawContext, but I’m unable to change it’s color.
Eg: let img = sym.image; img.tintColor = Color.white(); //Not sure if this is supposed to work, but doens't throws any error. dc.drawImageAtPoint(img, new Point(x, y))
Draws a black symbol .
I recently ran into this with an SFsymbol that was colored by default. It doesn’t look like there is a way that you can tint an image object when you’re drawing it to a DrawContext, you can only tint a WidgetImage.
Notice in the docs for image you can’t change an image at all. It would be nice if drawImageAtPoint had an optional tint parameter,