Making Glow effect to font - ios

I wonder if anybody have an example for Glow effect for font? I tried to look in NSAttributedString but I don't find in attribute for glowing text.

Try this:
#include <Quartzcore/Quartzcore.h>
.......
yourLabel.layer.shadowColor = [[UIColor glowColor] CGColor]; //Replace glowColor with the desired color (redColor, greenColor, etc.)
yourLabel.layer.shadowOffset = CGSizeMake(0.0, 0.0); //The glow starts from the center
yourLabel.layer.shadowRadius = 20.0; //You can change this to the desired amount
yourLabel.layer.shadowOpacity = 0.5; //You can change this to the desired amount
yourLabel.layer.masksToBounds = NO; //Keep this the same to avoid shadow being clipped by the label bounds
Hope this helps!

Related

CAShapeLayer : Identify shape : Add CATextLayer in that shape

I have SVG file and i was able to access SVG's shapes using SVGKit.
Now, I have CAShapeLayer which may contain circle, square or any closed shape.
I want to add CATextLayer on CAShapeLayer in such way that text should not cross the defined shape.
Here is the example of crossing CATextLayer on CAShapeLayer :
It's crossing just because, CATextLayer is starting from 0 position of CAShapeLayer which contains circle in particular this case.
In my case, CAShapeLayer can contain any closed shape. It can be oval also.
How can I identify shape inside CAShapeLayer? or How can I apply path to CATextLayer? which will makes sure text will be drawn inside shape?
Here is code to add CATextLayer On CAShapeLayer:
-(CATextLayer *)addTrackerNumberToLayer:(NSString *)numbers{
self.numbersTextLayer = [CATextLayer new];
self.numbersTextLayer.foregroundColor = [UIColor blackColor].CGColor;
self.numbersTextLayer.font = (__bridge CFTypeRef _Nullable)([UIFont boldSystemFontOfSize:15]);
self.numbersTextLayer.fontSize=25;
self.numbersTextLayer.anchorPoint = CGPointZero;
self.numbersTextLayer.frame = CGRectMake(self.parentShapeLayer.bounds.size.width*0.05, self.parentShapeLayer.bounds.size.height*0.05, self.parentShapeLayer.bounds.size.width*0.90, self.parentShapeLayer.bounds.size.height*0.30);
self.numbersTextLayer.position = CGPointMake(self.parentShapeLayer.bounds.size.width*0.05,self.parentShapeLayer.bounds.size.height*0.05);
self.numbersTextLayer.alignmentMode = kCAAlignmentCenter;
[self.parentShapeLayer addSublayer:self.numbersTextLayer];
}
Use isWrapped property of CATextLayer this determines whether the text is wrapped to fit within the receiver’s bounds.
-(CATextLayer *)addTrackerNumberToLayer:(NSString *)numbers{
self.numbersTextLayer = [CATextLayer new];
self.numbersTextLayer.foregroundColor = [UIColor blackColor].CGColor;
self.numbersTextLayer.font = (__bridge CFTypeRef _Nullable)([UIFont boldSystemFontOfSize:15]);
self.numbersTextLayer.fontSize=25;
self.numbersTextLayer.anchorPoint = CGPointZero;
self.numbersTextLayer.frame = CGRectMake(self.parentShapeLayer.bounds.size.width*0.05, self.parentShapeLayer.bounds.size.height*0.05, self.parentShapeLayer.bounds.size.width*0.90, self.parentShapeLayer.bounds.size.height*0.30);
self.numbersTextLayer.position = CGPointMake(self.parentShapeLayer.bounds.size.width*0.05,self.parentShapeLayer.bounds.size.height*0.05);
self.numbersTextLayer.alignmentMode = kCAAlignmentCenter;
[self.numbersTextLayer setWrapped:YES];//User Wrapped to YES to imbound the text to fit in the region.
[self.parentShapeLayer setMasksToBounds:YES];
[self.parentShapeLayer addSublayer:self.numbersTextLayer];
return self.numbersTextLayer;
}

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?

How to set shadow gradient image on UIImageView iOS

Hey I'm new to iPhone and I have been trying to set shadow for UIImageView using shadow gradient image i.e. "Image-Shadow.png" using below code.
imageView.layer.shadowColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:#"Image-Shadow.png"]].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0, 1);
imageView.layer.shadowOpacity = 1;
imageView.clipsToBounds = NO;
imageView.layer.shouldRasterize = YES;
My problem is, i am not getting shadow in my UIImageView using above code. Can you please tell me that is this the correct way to add shadow image in UIImageView or it is possible with some other way?
Problem is with the image. I don't think you can provide a pattern image to create a shadow!
Give a proper color like [UIColor blackColor].CGColor and it should work.
The problem is with this line:
imageView.layer.shadowOffset = CGSizeMake(0, 1);
where you are setting the shadow, but not giving it a visible space to display itself.
Positive or negative values should be given to both parameters.
Positive values stretch "down" and "to the right" of your view, negative values stretch "to the left" and "to the up" of your view.
here is my solution as per my requirement :
//set shadow gradient on image view
UIView *shadowView = [[UIView alloc] initWithFrame:imageView.frame]; //add view behind the image view
shadowView.layer.contents = (id) [UIImage imageNamed:#"Image-Shadow.png"].CGImage;
[imageView addSubview:shadowView];
Thanks to all.

Put text in UIView programmatically

Within my app, I use drawRect to draw some text within a UIImage. It writes multiple things in multiple places.. Later, I try to erase some of the text by using
CGContextSetBlendMode(context, kCGBlendModeClear);
CGPoint daPoint = CGPointMake(second.x + 20, second.y + 20);
NSDictionary *textAttributes = #{ NSFontAttributeName: [UIFont boldSystemFontOfSize:25.0],
NSForegroundColorAttributeName: [UIColor clearColor] };
[textString drawAtPoint:daPoint withAttributes:textAttributes];
This works almost perfectly, except there is a small thin stroke left over from the text. I use the same code to draw the text, as I do to erase, except when i'm drawing I use kCGBlendModeNormal. How would I get rid of it completely? Can I draw a box and fill it using kCGBlendModeClear? This is what it looks like currently before erasing:
After erasing:
I would get the bounding rect of the text and then call CGContextClearRect and then fill with the background color if you think that "erasing" the text is really necessary. If you simply "redraw" your rect, that might be another way to solve this problem.
Here's how to get that bounding box for clearing:
CGSize textSize = [textString sizeWithAttributes:textAttributes];
CGRect textFrame = CGRectMake(daPoint.x, daPoint.y, textSize.width, textSize.height);
Hope this helps!

set label border in iphone

How can I set label's border which is dynamically generated (Not from Interface Builder)?
you can do it by
Label.layer.borderColor = [UIColor whiteColor].CGColor;
Label.layer.borderWidth = 4.0;
before this you need to import a framework QuartzCore/QuartzCore.h
Swift version
Set label border
label.layer.borderWidth = 2.0
Set border color
label.layer.borderColor = UIColor.blueColor().CGColor
Use rounded corners
label.layer.cornerRadius = 8
Make background color stay within rounded corners
label.layer.masksToBounds = true
You can also try to subclass your label and override the drawRect: method to draw or a border or whatever you like:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] setStroke];
CGContextStrokeRect(context, self.bounds);
}
I'm not sure you can by default with UILabel. You might want to consider using a read-only (field.editing = NO) UITextField and setting it's borderStyle (which can be done programmatically using a UITextBorderStyle). That may be a little 'heavy' though. Another option may be to sub-class UILabel to draw your border.
Alternatively, and depending on your needs this may be better, use the backing CALayer and draw a border using it's borderColor and borderWidth properties.

Resources