How do I change the color of the unselected/normal segment text in an iOS 13 segmented controller? - uisegmentedcontrol

I am trying to configure an instance of the UISegmentedController class so that I can set the color of the text in the unselected segment from the default of black to white for a two-segment segmented controller. But I can't find any way of doing it. I have tried using the setTitleTextAttributes(_,for:)method but I cannot find a suitable NSAttributedString.Key attribute to change the text color.

This works for me in a playground:
import UIKit
import PlaygroundSupport
let seg = UISegmentedControl(items: ["foo", "bar"])
seg.setTitleTextAttributes([.foregroundColor: UIColor.red], for: .normal)
seg.setTitleTextAttributes([.foregroundColor: UIColor.blue], for: .selected)
seg.selectedSegmentIndex = 0
PlaygroundPage.current.liveView = seg

Related

Manim / Cairo : color discrepancies

I have some discrepancies in terms of brightness, saturation and hue when using a jpg picture in Manim.
I have a picture which color profile/space is Adobe RGB. I create it, edit it and save it that way. All of my apps previewing the picture are more, or less consistent with the original (enough to be acceptable). Including a movie export test from After effects. Even the image previewer of VS Code shows the image correctly. But when I render it with Manim, it's no good. Way too bright, oversaturated with a slight shift in hue and as if it was downgraded in terms of quality (some subtle but weird color artifacts are showing). You can tell something is off.
Granted, the picture I try to use is an abstract background with subtle gradients of color and light but still. The overall difference and loss in quality are sufficiently there not to be acceptable.
I know that managing color spaces and profiles is a bit tricky and is an art in and on itself but the problem here is that the image is consistent everywhere so far but in Manim's rendered MP4 file.
The only thing I've seen in the doc related to color spaces is this parameter "image_mode". I tried to set it both to RGB and RGBA (only two options available) in the Manim script but it doesn't change anything.
I suspect it's a feature that is more related to the renderer (Cairo) or the MP4 export parameters than Manim itself or maybe it downgrades jpg to gif/png before it renders the picture in Mp4 ? I don't know and I don't know what to do with that anyway since I don't know how to parameter any of this within Manim itself. I can't see any parameters that allow to edit any of this in the doc.
Maybe a plugin could add some functionalities or something ?
Any help would be appreciated.
PS: the picture is 4k and I render it in 4k in Manim, so it should be a pixel to pixel match.
Here is my Manim script:
from manim import *
class Graph(Scene):
def construct(self):
bg = ImageMobject("media/background/13.jpg")
self.add(bg)
self.wait()
And here are the relevant parts of my manim.cfg
[CLI]
write_to_movie = True
format = mp4
save_last_frame = False
write_all = False
save_pngs = False
save_as_gif = False
preview = False
background_color = #212021
background_opacity = 1
renderer = cairo
use_webgl_renderer = False
webgl_renderer_path =
use_opengl_renderer = False
enable_gui = False
gui_location = 0,0
fullscreen = False
window_size = default
window_monitor = 0
force_window = False
use_projection_fill_shaders = False
use_projection_stroke_shaders = False
movie_file_extension = .mp4
frame_rate = 60
frame_size = 3664,1980
pixel_height = 1980
pixel_width = 3664
max_files_cached = 100
flush_cache = True
disable_caching = True
disable_caching_warning = False
enable_wireframe = False
dry_run = False
tex_template =
plugins =
TL;DR: Some random pointers, but no answer to the question.
I have no clue about manim, so I just went searching for "JPEG" in its source code. That brought me to https://github.com/3b1b/manim/blob/3c7a38660af41478e1561073a5319b23fb6b7787/docs/source/documentation/custom_config.rst#L59 which says
The directory for storing raster images to be used in the code (including .jpg, .jpeg, .png and .gif), which will be read by ImageMobject.
Okay, what's ImageMobject? Another search found the place where it loads images and apparently this just uses the Python library PIL to call PIL.Image.open: https://github.com/3b1b/manim/blob/669182944da040c227ccfd018250ee2bbc49649d/manimlib/mobject/types/image_mobject.py#L31
Okay, so does this support color profiles? I don't know. What does this question even mean? You are loading some color image that contains a color profile and it ends up being part of a movie... Should the movie now use that color profile?
Another random pointer that I found is PIL/Pillow decode icc profile information but that didn't really help. All I can say is: The manim code that I found doesn't do anything fancy with color profiles.

tk.Text: Tag Font

Is there a way to get a proper Font instance out of a tag, so I can change just the size? I know I can dump it in tk.font.Font but that seems really inefficient.
for tag in self.tag_names():
#I need `f` to be a Font instance, not just a string
f = self.tag_cget(tag, 'font')
If you used font objects to create the tags, then you can get the font name from the tag and then use nametofont to convert it to an instance of tkinter.font.Font. However, this only works if the tag has a font associated with it, and if the font is a font object rather than shorthand notation (eg: ("Helvetica", 24, "bold")).
from tkinter.font import nametofont
...
for tag_name in self.tag_names():
font_name = self.tag_cget(tag_name, "font")
if font_name:
font = nametofont(font_name)
size = int(font.cget("size"))
font.configure(size = size + delta)
One method is to premake all of the Font instances and assign the instances to the applicable tag's font option. When you want to change the sizes, loop over the stored Font instances, and change their sizes directly. Every tag that uses your Font instances will change accordingly.

How to use icon font with Jetpack Compose?

in before xml in TextView we have
holder.binding.iconInfo.text = "&#x${iconValue}"
and set out icon font to it with typeface dose anyone can help same thing but with jetpack compose
The specific syntax you mention that can be used with TextViews is due to the fact that XML is used when defining layouts. That is an XML numeric character entity that specifies a character with its unicode value in hexadecimal notation.
So it is not related to TextViews, layouts, fonts or icons.
If you want to do the same with a String in Kotlin and the character value is dynamic, you can do something like this
val text = "${Char(iconValue)}"
In Compose a custom font can be defined either as part of your Theme -> Typography and then used as text style or you can define it directly like this
val fontFamily = FontFamily(
// If you have the font in resources
Font(R.font.my_font_normal, weight = FontWeight.Normal),
Font(R.font.my_font_bold, weight = FontWeight.Bold),
Font(R.font.my_font_italic, weight = FontWeight.Normal, style = FontStyle.Italic),
// If you are loading the font at runtime from a file
Font(File(...), weight = FontWeight.Normal),
// ...
)
// Use with Text composable
Text(text = text, fontFamily = fontFamily)

Custom font does not render correctly when using ShowText

I have a custom view in which I am trying to draw text using a Windows font (calibri.ttf). However, I am getting different behaviour between using the DrawString & ShowText functions.
I have embedded the font as part of the app (added it to the UIAppFonts list & set it's build action to Content) and I all works fine when I use the DrawString method from my custom UIView e.g.
Code
public override void Draw (System.Drawing.RectangleF rect)
{
base.Draw (rect);
DrawString("Calibri font via DrawString", new RectangleF(10, 10, 100, 100), UIFont.FromName("Calibri", 16f));
}
Result
However, if I attempt to draw the same text this time using ShowText it appears as if the font isn't encoding the text correctly, or the character mapping is wrong.
Code
public override void Draw (System.Drawing.RectangleF rect)
{
base.Draw (rect);
var ctx = UIGraphics.GetCurrentContext();
ctx.SelectFont("Calibri", 16f, MonoTouch.CoreGraphics.CGTextEncoding.FontSpecific);
ctx.ShowTextAtPoint(10, 10, "Calibri font via ShowText using SelectFont");
}
Result
UPDATE - Here is what I get if I use MacRoman encoding instead of FontSpecific:
I have also tried loading in the font manually and using that but then I get nothing at all, it's like it doesn't recognise the font e.g.
var fontPath = NSBundle.MainBundle.PathForResource("calibri", "ttf");
var provider = new CGDataProvider(fontPath);
var font = CGFont.CreateFromProvider(provider);
var ctx = UIGraphics.GetCurrentContext();
ctx.SetFont(font);
ctx.ShowTextAtPoint(10, 20, "Calibri font via ShowText using SetFont");
I know that DrawString is UIKit & ShowText is CG (Quartz) so I understand that there may be differences. However, from what I gathered the only difference with DrawString was it corrected the issue with the difference in Offset (CG being at the bottom left/UIKit being at the top left).
NOTE - The underlying problem I have is I need to use this font to draw text onto a layer via a custom CALayerDelegate. I don't have access to the DrawString function from in there, therefore, the only way I can see to draw the text is via ShowText. Alternative solutions are welcome!
This really looks like an encoding issue. Try using CGTextEncoding.MacRoman instead of CGTextEncoding.FontSpecific (even Arial wouldn't render, as expected, with FontSpecific).
UPDATE Oct 12th
a) your last code sample won't work because Apple doc specifically states not to use SetFont and ShowText together. Quote follow:
Quartz uses font data provided by the system to map each byte of the array through the encoding vector of the current font to obtain the glyph to display. Note that the font must have been set using CGContextSelectFont. Don’t use CGContextShowText in conjunction with CGContextSetFont.
b) the CGTextEncoding.MacRoman code works with several other iPhone-supplied fonts. I'm beginning to suspect it's something about the Calibri.ttf font itself that is not supported by iOS.

Problems encountered in changing a CRichEditCtrl selection color

I have written the following code after creating the CRichEditCtrl
// 06112010 : The following code was added to highlight the textselection in black color instead of the default blue color of CRichEditCtrl. - 1311
{
m_EditControl.SetSel(0,100);
CHARFORMAT2 cf1;
cf1.cbSize = sizeof(CHARFORMAT2);
m_EditControl.GetSelectionCharFormat(cf1);
cf1.dwMask = CFM_BACKCOLOR ;
cf1.dwEffects &= ~CFE_AUTOBACKCOLOR;
cf1.crBackColor = RGB(0,0,0);
m_EditControl.SetSelectionCharFormat(cf1);
m_EditControl.Invalidate();
}
After this I am adding text, but the selection still comes in blue color instead of Black. Could someone please tell me what I am doing wrong??
Thanks,
DeV
You can't do it using SetSelectionCharFormat, which will only reformat the selected text. What you're asking for is an owner draw rich edit control, which is going to be more work than just deriving your own custom window from CWnd and implementing your own WM_PAINT handler.

Resources