I have the following code:
UIColor *borderColor = [UIColor colorWithRed:182 green:10 blue:96 alpha:1.0];
[viewImage.layer setBorderColor:borderColor.CGColor];
[viewImage.layer setBorderWidth:3.0];
[productView addSubview:viewImage];
where viewImage is my UIImageView and productView is my UIView.
I want to get this color , but all I am getting is this color . I tried different values, and all the colors that I am getting is either white, red, black, yellow, or blue. I can't get any other colors, doesn't matter what values I enter. I tried colorWithHue:Saturation:Brightness and I have the same issue.
I am using this on iOS 6 SDK.
What am I doing wrong and how can I fix it?
#import <QuartzCore/QuartzCore.h>
[imageView.layer setBorderColor: [[UIColor blackColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
The values for red green and blue should be beween 0.0 and 1.0.
From UIColor doc:
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
Try this
UIColor *color = [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1];
Swift version 2.11 (Xcode 7.2.1):
let borderColor = UIColor(red:0, green:0, blue:0, alpha:1.0)
viewImage.layer.borderColor = borderColor.CGColor
viewImage.layer.borderWidth = 2.0
Related
I am following Brad's answer to apply glow effect in my CALayer text.
Here is my code:
- (void)drawLayer:(CALayer *)theLayer inContext:(CGContextRef)context
{
UIGraphicsPushContext(context);
UIFont *font = [UIFont fontWithName:#"Verdana" size:11.0f];
CGRect rect = CGRectMake(theLayer.bounds.origin.x + 5, theLayer.bounds.origin.y + 5, theLayer.bounds.size.width - 10, theLayer.bounds.size.height - 10);
NSString * textToWrite = #"Some text";
UIColor *color = [ UIColor colorWithRed: (100.0f) green: (50.0) blue:(200.0f) alpha: 1.0f ];
CGContextSetFillColorWithColor(context, color.CGColor); //this has no effect!!!
CGContextSetShadowWithColor(context, CGSizeMake(0.0, 0.0), 2.0f, [UIColor greenColor].CGColor);
[textToWrite drawInRect:rect withFont:font
lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
UIGraphicsPopContext();
}
I am getting a decent green glow here. However I want the text to have its own color too, apart from glow. For this I am using color variable here, along with CGContextSetFillColorWithColor. But it seems to have NO effect. The text seems white, with green glow. I want text with main color = color and glow=green.
What should I do?
I'm confused by your color... I think when declaring red green and blue in objective-c you set values that are up to 1.0 being the maximum (like you did with alpha) so when you give them their true 255 hex value you then divide by 255. Your color should be white since all 3 values are so far above the maximum... Maybe I'm wrong though first try these two codes...
Replace your current FillColorWithColor code with this:
[[UIColor colorWithCGColor:color] set];
(or maybe this...)
[[UIColor colorWithCGColor:color.CGColor] set];
If they don't work then try them while also changing your color code to this:
UIColor *color = [ UIColor colorWithRed: (100.0f/255.0f) green: (50.0f/255.0f) blue:(200.0f/255.0f) alpha: 1.0f ];
I add shadow to the UIView:
[blurView.layer setCornerRadius:kCornerRadius];
blurView.layer.masksToBounds = NO;
blurView.layer.shadowColor = [[UIColor redColor] CGColor];
blurView.layer.backgroundColor = blurView.layer.shadowColor;
blurView.layer.shadowPath = [UIBezierPath
bezierPathWithRoundedRect:CGRectMake(-2.0*kCornerRadius, -2.0*kCornerRadius, blurView.bounds.size.width+4.0*kCornerRadius, blurView.bounds.size.height+4.0*kCornerRadius)
cornerRadius:kCornerRadius].CGPath;
blurView.layer.cornerRadius = kCornerRadius;
blurView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
blurView.layer.shadowRadius = kCornerRadius;
blurView.layer.shadowOpacity = kOpacity;
blurView.layer.opacity = 1.0;
This part of code gives me a this view, like a uiview is blured:
When I try change opacity of blurView.layer (for example to 0.5), I get unexpected view:
As you can see - I get a sharp edges of uiview.
I think, shadow opacity is a part of opacity of layer - it's a cause of this 'error'. Can anybody help me to fix this? May be can I merge layers before change opacity of blurView.layer or something like this?
UPD
With this fix:
blurView.layer.shadowColor = [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5] CGColor];
I get this:
UPD
Answer is using setShouldRasterize method:
Thanks everybody!
[blurView.layer setShouldRasterize:YES];
The answer is using this code line:
blurView.layer.shouldRasterize = YES;
Maybe you could try putting this in?
blurView.layer.shadowColor = [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5] CGColor];
What happens if you put this :
blurView.layer.shadowOpacity = 1.0;
blurView.layer.opacity = 0.5;
I think that you might be setting the shadow opacity to 0.5 and then the whole layer to 0.5, making the shadow twice as transparent?
(or I'm completely wrong!)
I am trying to have an UIImageView bordered like the following:
I have tried using:
[imageView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[imageView.layer setBorderWidth: 2.0];
but then you can't see that gray border on the outside. It has that gray shadow effect on the outside.
How do I do this?
Take a look at the shadow properties of CALayer.
[imageView.layer setShadowOffset:CGSizeMake(-1.0, -1.0)];
[imageView.layer setShadowOpacity:0.5];
This question about adding shadows to UIImageView might help
imageView.layer.shadowOpacity=0.6;
imageView.layer.shadowRadius = 0.0;
imageView.layer.shadowColor = [UIColor grayColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(-2.0, 1.0);
The default UIButton round rectangle is that dark blue. I want my cell's text in a table to match this blue color.
I am using this code but the only blue I can find is a bright blue...
cell.textLabel.textColor = [UIColor blueColor];
The system button text color for iOS 7 and above is:
Swift:
UIColor(red: 0, green: 0.478431, blue: 1, alpha: 1)
Objective-C:
[UIColor colorWithRed:0 green:0.478431 blue:1 alpha:1]
Use this code to set the color using RGB value
cell.textLabel.textColor = [UIColor colorWithRed:.196 green:0.3098 blue:0.52 alpha:1.0];
The color in iOS6 is:
[UIColor colorWithRed:0.22 green:0.33 blue:0.53 alpha:1.0]
I am trying to add custom color like how we do in HTML:
<body bgcolor=#ffffff> </body>.
Can we have a similar kind of custom color combination for showing in cells on iPhones?
cell.backgroundColor = [ UIColor whiteColor]; but instead of whiteColor wanna use #ffffff.
How can I implement this?
Use UIColor colorWithRed:green:blue:alpha:. Colors are 0.0 to 1.0, something like this for bright red:
cell.backgroundColor = [UIColor colorWithRed:1.0f green:0 blue:0 alpha1];
For a color such as "808182" it would be:
[UIColor colorWithRed:128/255.0f green:129/255.0f blue:130/255.0f alpha:1];