How to get the name of a UIColor? - nsstring

I have an array of UIColors like
[UIColor blueColor];
is it possible to get the name "blue" from that UIColor, to display it in a string?

There's nothing built in to UIKit, but Erica Sadun's uicolor-utilities library adds similar functionality.

You can get RGB and Alpha of the UIColor, if you want.

A list of color names can be obtained using runtime.
See my question: How to get all Color methods of UIColor?
You can also use string methods to convert 'xxxColor' to 'xxx' if needed.

Related

SimpleDom Search Via plaintext Text

I am using "PHP Simple HTML DOM Parser" library and looking forward to find elements based on its text value (plaintext)
For example i need to find span element using its value "Red".
<span class="color">Red</span>
I was expecting bellow code to work but seems that it just replaces the value instead of searching it.
$brand = $html->find('span',0)->plaintext='Red';
I read Manual and also i tried to look in library code itself but was not able to find the solution, kindly advise if i am missing something or it is simply not possible to do via Simple Html DOM Parser.
P.S
Kindly note that i am aware of other ways like regex.
Using $html->find('span', 0) will find the (N)th span where in this case n is zero.
Using $html->find('span',0)->plaintext='Red'; will set the plaintext to Red
If you want to find the elements where the text is Red you could use a loop and omit the 0 to find all the spans.
For example, using innertext instead of plaintext:
$spansWithRedText = [];
foreach($html->find('span') as $element) {
if ($element->innertext === "Red") {
$spansWithRedText[] = $element;
}
}

How to get image of country based on country code in Xamarin.Forms?

I have country code(i.e USA). I want to get image of country.
There are lot of sources, few of them:
https://github.com/gosquared/flags
https://github.com/hjnilsson/country-flags
https://github.com/linssen/country-flag-icons
https://github.com/lipis/flag-icon-css/tree/master/flags (svg)
....
Perhaps the easiest approach, without using any external assets, would be to just use the Unicode flags in a label, for example this is the Unicode flag of Andorra: 🇦🇩

Chronoforms 6 data mask options

On Chronoforms6 there is an option to provide data masking for text fields.
I used the following entry in the Entry parameters:
data-inputmask='mask' : '*{1,30}'
What I also need is to allow spaces and - characters.
The above only allows alphanumerics.
Any hint on how to do this?
ChronoForms uses Robin Herbots InputMask library - please see the documentation on GitHub here. A Regexp mask or a custom format might solve your problem.

This regex is not right

I am trying to use regex generators to create an expression, but I can't seem to get it right.
What I need to do is find the following type of string in a string:
community_n
For example, within the string which may be
community community_1 community_new_1 community_1_new
from that, I just want to extract community_1
I have tried /(community_\\d+)/, but that is clearly not right.
Try adding word boundries, so
/(\\bcommunity_\\d+\\b)/
Try using the regex (community_\d+).
Though I could be incorrect since I don't know which language you are using.
(For some reason I cannot add comments, I can only answer questions).

How to Convert Qcolor value to hex value?

I have implemented a QColor dialog box which opens on certain condition. To get the selected color after final selection I use the method selectedColor() which returns the value in QColor. When I print that value, it's like this:
<PyQt4.QtGui.QColor object at 0x01DD7880>
I want color value in hex value like this: #DFDFDF (for grey). If it's not hex, correct me.
Is there any function to convert that?
Any suggestions welcome.
You need to print selectedColor().name() to print the actual color value in hex. See the QColor Documentation
To amplify a bit, maybe confuse, maybe clarify... (For Python newbies)
color = QColorDialog.getColor(pWidget.textBackgroundColor(), pWidget, 'Get Text Highlighting Color')
The above will return a QColor using the QColorDialog, for those of us who don't want to be stuck with named colors like 'Blue', 'red', green etc.
fg = color.name()
In this case I am converting the QColor to a string HEX for use in a style sheet.
Widget.setStyleSheet('background-color: ' + bg + ';color: ' + fg)
This is how such a converted value can be used in a style sheet.
Note how to concatenate more than one stylesheet attribute. Also, side note, sometimes changing one attribute cancels previous changes to others.

Resources