How to set box filled color value in swift xcode - swift

How to set color code value in swift UIColor.red
With box of color filled with red.
example coding
label.textColor = UIColor.red // Coding
label.textColor = a small box with color red filled??

The thing you're looking for is color literal.
Type color literal as a value of label.textColor and select Color Literal from the dropdown.
It will look something like this,
Double tap on the white box that appeared. A color palette will open like,
Select whatever color you want from the color palette. It will finally look something like,
Hence the box of color filled with red..😊

Related

How can I make a GUI.Toggle font size and color to be bigger and in black like the example in the screenshot?

The script is EditorWindow type:
What I did inside OnGUI:
void OnGUI()
{
GUIStyle myToggleStyle = new GUIStyle(GUI.skin.toggle);
myToggleStyle.fontSize = 14;
Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
myToggleStyle.font = myFont;
myToggleStyle.normal.textColor = Color.black;
GUI.Toggle(new Rect(5, 10, 200, 60), false, "Select All", myToggleStyle);
}
The screenshot show the result of my toggle at the top the "Select All" and under it the toggle how I want my one to be the same. A bit bigger but same color and font. If the bottom toggle size is 11 or 12 then my one should be 13 or 14. But as long as I make my toggle font size bigger the color is not the same as the bottom one and both are black.
The bottom one is created by EditorGUILayout.BeginToggleGroup and EditorGUILayout.EndToggleGroup but I want to make a single one not a group.
The main goal is to make a single toggle just like the bottom one by size and color.
I think you just need to set the font style to bold:
myToggleStyle.fontStyle = FontStyle.Bold;

Changing value in if statement

I'm trying to iterate through a column in numbers and change the background color of a cell, if the cell has a certain background color.
repeat with i from 11 to the count of cells by 6
if background color of cell i is {17990, 47031, 42919} then
set background color of cell i to {65535, 0, 0}
end if
end repeat
unfortunately, this does not do anything. The script just stops without Error. Help please!
There seems to be a bug in Numbers app where is not reporting the colors correctly. I set the background colors of columns A and B to your chosen value {17990, 47031, 42919}, but when I asked the script to return the colors, it returned the value {17990, 47030, 42919}. Because of this, I had the script check for both values and to act accordingly.
I added a dialog pop-up giving you the option to choose which column to change the cell colors.
tell application "Numbers"
set ifColor to {17990, 47031, 42919}
set ifColor2 to {17990, 47030, 42919}
set changeToColor to {65535, 0, 0}
tell its document 1
set theColumns to name of columns of table "Table 1" of active sheet
set chosenColumn to item 1 of (choose from list theColumns with title "Choose The Column" with prompt "Choose The Column")
set cellCount to count of cells of column chosenColumn of table "Table 1" of active sheet
repeat with i from 11 to cellCount by 6
set thisCell to cell ((chosenColumn & i) as string) of table "Table 1" of active sheet
if background color of thisCell is ifColor or background color of thisCell is ifColor2 then
set background color of thisCell to changeToColor
end if
end repeat
end tell
end tell
Here's the table I started with, having coloured the background of one cell magenta, i.e. {65535,0,65535}.
Then I ran this code:
use NumbersApp : application "Numbers"
property document : a reference to document 1 of NumbersApp
property sheet : a reference to active sheet of my document
property table : a reference to table 1 of my sheet
repeat with c in (a reference to every cell of my table)
if c's background color = missing value then ¬
set c's background color to {65535, 65535, 0}
if c's background color = {65535, 0, 65535} then ¬
set c's background color to {65535, 65535, 65535}
end repeat
I was expecting the majority of cells to turn yellow, and my magenta cell to turn white:
Hm...
My magenta cell is still looking far too magenta. So I decided to check just how magenta it really is:
return the background color of cell "C7" of my table
--> {64587, 609, 65480}
Well, that's not what I set it to, but it's pretty magenta, though I now see why it didn't turn white.
Next I decided to check the background colour of one of the yellow cells, that you have just seen me programmatically turn to a very specific kind of yellow:
return the background color of cell "D10" in my table
--> {65534, 65531, 2689}
Again, it is yellow, but not the yellow I told it to be.
Finally, I used the colour value just returned to try and target those cells and turn them black:
set the background color of every cell in my table ¬
whose background color is {65534, 65531, 2689} ¬
to {0, 0, 0}
Zilch. They are still very sunnily yellow.
Conclusion
Bug in AppleScript. I've submitted a bug report to Apple. I suggest you do the same.
#wch1zpink: {17990, 47031, 42919} --> {17990, 47030, 42919}
Looks like a rounding error introduced when converting integers to floating point numbers and back again. (AppleScript dates from the days of QuickDraw, which represented RGB values as UInt16, whereas Numbers is a Cocoa app, and Cocoa's NSColor uses CGFloat.) That's unavoidable, being a fundamental limitation of how CPUs do math (e.g. 0.7 * 0.7 = 0.49 --> false!).
The solution is to check the numbers are equal within an acceptable margin of error:
on areRealsEqual(n1, n2, toleranceMargin)
return n1 > n2 - toleranceMargin and n1 < n2 + toleranceMargin
end areRealsEqual
on areColorsEqual(c1, c2)
repeat with i from 1 to length of c1
if not areRealsEqual(item i of c1, item i of c2, 5) then return false
end repeat
return true
end areColorsEqual
set expectedColor to {17990, 47031, 42919}
set foundColor to {17990, 47030, 42919}
areColorsEqual(expectedColor, foundColor)
--> true

JavaFX - Label text color on negative text value

I would like to change text color of my Label in case its text value is a negative number (or starts with a '-'). Is there a proper binding to make it works?
No, you need to create it yourself, e.g.
Label label = ...
IntegerExpression value = ...
label.textProperty().bind(value.asString());
label.textFillProperty().bind(Bindings.when(value.lessThan(0))
.then(Color.RED)
.otherwise(Color.BLACK));
If you've don't have a expression that allows you to create a condition in this way you could of course also create a binding that depends on the Label's text property:
Label label = ...
label.textFillProperty().bind(Bindings.createObjectBinding(() -> label.getText().startsWith("-")
? Color.RED
: Color.BLACK,
label.textProperty()));

Unity is returning material color slightly wrong

I have this mini task in my game where you need to click trophies to change color of the wood on them. I have two arrays of colors, one is an array containing all possible colors and the other one contains four colors (the answer) as follows:
I've double checked that the colors are equal between the two arrays. For example the purple in Colors-array has exactly the same r, g, b & a values as the purple in the Right Order-array.
To check whether the trophies has correct color I just loop through them and grab their material color. Then I check that color against the Right Order-array but it's not quite working. For example when my first trophy is purple it should be correct, but it's not because for some reason Unity is returning slightly different material color than excepted:
Hope somebody knows why this is happening.
When you say, they are exactly same color, I assume you are referring rgb values from Color Inspector, which are not precise values.
Now I dont know what could be causing in different values of colors but
You can write an extension method to compare the values after rounding them to closest integer.
public static class Extensions
{
public static bool CompareRGB(this Color thisColor, Color otherColor)
{
return
Mathf.RoundToInt(thisColor.r * 255) == Mathf.RoundToInt(otherColor.r * 255) &&
Mathf.RoundToInt(thisColor.b * 255) == Mathf.RoundToInt(otherColor.b * 255) &&
Mathf.RoundToInt(thisColor.g * 255) == Mathf.RoundToInt(otherColor.g * 255);
}
}
usage:
Color red = Color.Red;
red.CompareRGB(Color.Red); // true;
red.CompareRGB(Color.Green); // false;
Hope this helps.
I would use a palette. This is simply an array of all the possible colors you use (sounds like you have this). Record, for each "trophy", the INDEX into this array, at the same time you assign the color to the renderer. Also, record the index for each "button", at the same time you assign the color to the renderer.
Then you can simply compare the palette index values (simple integers) to see if the color matches.

Setting Table Border in Mircrosoft Word using AppleScript

When I try to set the line thickness of a table border, the result changes the line type to something undesired. Why is the line width parameter affecting the line style parameter? See the examples below and try them for yourself. I am using MS Office 2011 Word v14.2.3.
tell application "Microsoft Word"
set line style of (get border selection which border border bottom) to line width225 point
get line width of (get border selection which border border bottom)--test:results in line width150. Why? I just set it to line width225!
--width25 = fine dots
--width225 = cornered sine wave
--width50 = dashed line
--width75 = dash + 3 dots + dash
--width100 = 3 lines
--width150 = 2 lines
--width300 = single
--width450 = does not work
--width600 = does not work
end tell
If I run this on a table which has the settings that I want, in order to see what they are:
tell application "Microsoft Word"
get properties of (get border selection which border border bottom)
end tell
I get:
{class:border, visible:true, color index:no highlight, inside:false, line style:line style single, line width:line width225 point, art style:missing value, art width:missing value, color:{0, 0, 0}, color theme index:no theme color}
Which is correct. I should be able to copy those parameters to make my script work, but something happens when I try to set the line width (border thickness).
If you want to change the line thickness, use line width instead of line style, otherwise it's normal that it doesn't do what you expect.
set line width of (get border selection which border border bottom) to line width225 point
If you want to change the line style, you should use a value from this list : (
line style none, line style single, line style dot, line style dash small gap, and many more ...)