Setting UIITextView border color - ios

I would like to set the silver color for my UITextView border. I tried this:
theGroupTextLabel.layer.borderWidth = 3.5f;
theGroupTextLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
...but in the color option there are only some colors like whiteColor, BlackColor, Green...
What if I want silver?

You need to use RGB values for custom colors;
CGFloat nRed=128.0/255.0;
CGFloat nBlue=98.0/255.0;
CGFloat nGreen=53.0/255.0;
UIColor *myColor=[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1];
Choose RGB Values Here
Something around R:193 G:205 B:205 would be close to silver

You will just need to customize your color with RGB values because what you are seeing are just a handful of predefined colors for your convenience. This is an example of a custom color with RGB values.
[[UIColor colorWithRed:0.5f green:0.2f blue:0.7f alpha:1.0f] CGColor]; // Not actually silver
NOTE: Normally you will find a number between 0 and 255 for each value but this function takes floats so just take those number and divide it by 255 to get the float value of what you need.

Try to set you your color like this
theGroupTextLabel.layer.borderWidth = 3.5f;
theGroupTextLabel.layer.borderColor = [[UIColor colorWithRed:(RedRGB.0/255.0)
green:(GreenRGB.0/255.0)
blue:(BlueRGB.0/255.0)
alpha:(AlphaRGB.0/255.0)] CGColor];

Related

How to give #3f51b5 color code programmatically for shadow color in ios

I want to make shadow color with #3f51b5.
How can I do that. hope your help. this type cannot use to do that.
cell.layer.shadowColor = [UIColor purpleColor].CGColor;
you need to set shadow first
cell.layer.shadowRadius=8;
cell.layer.shadowOffset=CGSizeMake(-1, -1);// this make top left shadow
cell.layer.shadowOpacity=1;
cell.layer.shadowColor = [UIColor colorWithRed:0.2471 green:0.3176 blue:0.7098 alpha:1.0].CGColor;
after setting the color give shadow radius,offset and opacity, convert the color to rgba and use this
cell.layer.shadowColor = [UIColor colorWithRed:0.2471 green:0.3176 blue:0.7098 alpha:1.0].CGColor;
cell.layer.shadowRadius=10;
cell.layer.shadowOffset=CGSizeMake(1, 1);
cell.layer.shadowOpacity=1;
if you want to use hex color only use this
How can I create a UIColor from a hex string?

UIColor display not exactly correct?

I input this in viewDidLoad
self.view.backgroundColor = [UIColor colorWithRed:231/255.0 green:77/255.0 blue:77/255.0 alpha:1.0];
and create label in xib , set color e74d4d(which convert to rgb is 231,77,77)
I want to show image on the website , but it tells me I need 10 reputation.
I debug the code,and find this,
(lldb) po self.view.backgroundColor
UIDeviceRGBColorSpace 0.905882 0.301961 0.301961 1
(lldb) po self.label.textColor
UIDeviceRGBColorSpace 0.87161 0.208926 0.237916 1
while you are passing value for UIColor always use float value.
self.view.backgroundColor = [UIColor colorWithRed:231.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
also use the same float value while you are converting to other format.
Edit: From the comments.
Dividing 231/255.0 and 231.0/255.0 are the same. Yes it is, but i have written that always pass float value means in for both values.
As user doesn't provided second conversation i thought function is using 255 for devision instead of 255.0 as a result it will be a integer value.
Try below code with RGBFromUIColor macro one by one, it will show different output.
self.titleLabel.backgroundColor = [UIColor colorWithRed:231/255 green:77/255 blue:77/255 alpha:1.0];
self.titleLabel2.backgroundColor = [UIColor colorWithRed:231.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
self.titleLabel3.backgroundColor = RGBFromUIColor(231, 77, 77);
self.titleLabel4.backgroundColor = RGBFromUIColor(231.0, 77.0, 77.0)
Now suppose macro for RGBFromUIColor is like below
#define RGBFromUIColor(r, g, b) \[UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
or like this
#define RGBFromUIColor(r, g, b) \[UIColor colorWithRed:(r)/255 green:(g)/255 blue:(b)/255 alpha:1]
The last RGBFromUIColor will not have same value in case it doen't devided by float i.e 255.0
Your issue is that the text lable colour is not the same as your background colour?
I suspect your problem is that you are setting the text color to e74d4d which is a 24 bit value, no transparency value (the A in RGBA and ARGB). Try ffe74d4d or e74d4dff which set the transparency to opaque (alpha to 1). Even better, simply set it the same way as you set the background color, and iOS will automatically set the transparency to opaque.
This may not be what you are experiencing, but it I have previously seen some color problems with the OS X Color Picker due to the color calibration on my display. Sometimes it seems to select the color components by display value and then convert them to sRGB, when you actually want no conversion at all.
I would try the either of the following:
Use the ‘RGB Sliders’ color picker panel.
Paint the color in an image without a color profile, open the image in Preview.app and use the pipette tool to select that color.

Color Palettes from storyboard used programmatically

I am building an app and I have multiple colors that I want a background to be depending on a predetermined factor. In my story boar I have tested and chosen the colors I wanted to use and I have put them in a palette on the color picker. First question can I programmatically call on the colors of the palette.
if that doesn't work I have already gotten the RGB values for each of the colors but when I try to go do this:
UIColor *myBlue =[UIColor colorWithRed:(60/255) green:(97/255) blue:(255/255) alpha:1.000];
self.navigationController.navigationBar.barTintColor = myBlue;
self.tabBarController.tabBar.barTintColor = myBlue;
it gives me the same color as of I go
[UIColor blueColor]
the reason I am creating my own color is because I don't want the predetermined colors but they are not showing up.
(This might be a zombie issue, but for anyone else curious)
This is actually a bug because you're performing integer division instead of floating point division. Dividing an int by an int throws away the remainder. You're code is functionally equivalent to:
UIColor *myBlue =[UIColor colorWithRed:0 green:0 blue:1 alpha:1.000];
Which of course is pure blue. To fix, force floating point division by making one of the numbers a float type. For example, you could change that line to:
UIColor *myBlue =[UIColor colorWithRed:(60/255.0) green:(97/255.0) blue:(255/255.0) alpha:1.000];

Can't implement changing of the bar colour in Core Plot Bar Chart

I have a simple Bar Chart with 12 bars. For this purposes I use Core Plot. I need to implement the method which colour the bars according to their values from light blue for minimum value to the dark blue for the max one.
Now I coloured all the bars in one colour:
self.barPlot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:100.0f / 255.0f green:192.0f / 255.0f blue:245.0f / 255.0f alpha:1.0f]];
I know the method which can set the colour for every bar:
-(CPTFill *)barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)idx;
But I can't find a good code for my purposes. Any help?
I post the code of the solved issue. Thanks for you support.
- (CPTFill *) barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index
{
CGFloat minValue = [[[[[PlotDataStore sharedInstance] docsCount] valueForKey:#"docs"] valueForKeyPath:#"#min.self"] floatValue];
CGFloat maxValue = [[[[[PlotDataStore sharedInstance] docsCount] valueForKey:#"docs"] valueForKeyPath:#"#max.self"] floatValue];
CGFloat value = [[[[[PlotDataStore sharedInstance] docsCount] valueForKey:#"docs"] objectAtIndex:index] floatValue];
CGFloat resultHue = (value * 0.6f / (maxValue - minValue)) + 0.4f;
return [CPTFill fillWithColor:[CPTColor colorWithCGColor:[UIColor colorWithHue:0.561f saturation:resultHue brightness:1.0f alpha:1.0f].CGColor]];
}
Have you tried this, does it work?
CPTGradient *barGradient = [CPTGradient gradientWithBeginningColor:[CPTColor blueColor] endingColor:[CPTColor blackColor]];
self.barPlot.fill = [CPTFill fillWithGradient:barGradient];
You can create a color from RGB values as you do already to calculate the fill in your first code example. To map values to colors you can for example set Red to 0, blue to 255 and then vary the green from 0 dark blue to 255 light blue. This is not the best solution, better would be to also change the blue value according to your value. You may want to use the OS X color well and try around a bit using the RGB sliders.

CorePlot CPT Color Apply Not All Color RGB Values

I am Working Core plot BarChart Apply the Bars Colors with RGB Does not Work..!
It is Working Only Major Colors like Red,Green,Blue,White,Purple..!
I am Try to apply Orange not applying.any one help me...!
[CPTColor colorWithComponentRed:255 green:163 blue:0 alpha:1]
It's Orange RGB Color Value.But, apply only Yellow Color....!
Components are floats from 0 - 1, do this:
[CPTColor colorWithComponentRed:255.0f/255.0f green:163.0f/255.0f blue:0.0f/255.0f alpha:1.0f]

Resources