Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uilabel with outline or stroke [duplicate]

I was wondering how can I create text stroke for UILabel ? is there any possible way ? enter image description here

thank you ,

#import <Foundation/Foundation.h>


@interface CustomLabel : UILabel {

 }

 @end

#import "CustomLabel.h"


@implementation CustomLabel

- (void)drawTextInRect:(CGRect)rect {

    CGSize shadowOffset = self.shadowOffset;
    UIColor *textColor = self.textColor;

    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(c, 22);

    CGContextSetTextDrawingMode(c, kCGTextStroke);
    self.textColor = [UIColor whiteColor];
    [super drawTextInRect:rect];

    CGContextSetTextDrawingMode(c, kCGTextFill);
    self.textColor = textColor;
    self.shadowOffset = CGSizeMake(0, 0);
    [super drawTextInRect:rect];

    self.shadowOffset = shadowOffset;
    //works fine with no warning 
}   

now the question is how can i use this subclass with a IBOutlet label on different viewcontrollers . is it right :

    label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 190, 190)];
like image 584
Mc.Lover Avatar asked Feb 23 '11 16:02

Mc.Lover


People also ask

How can I create a UILabel with strikethrough text?

Swift5 UILabel Extension. Use this code in that case. Show activity on this post. Change the text property to attributed and select the text and right click to get the font property. Click on the strikethrough.

How do I make my text bold on UILabel?

Write the following text in the label “Bold Regular”Double Click on Bold to select it, and then right click on it to see more options. Select font > Bold from that option. It should do the task.

What is UILabel?

A view that displays one or more lines of informational text.


1 Answers

It may be helpful to some to add that depending on font and characters, adding:

CGContextSetLineJoin(c,kCGLineJoinRound);

can prevent artifacts from too large a stroke applied to too sharp a character.

like image 169
Leon Avatar answered Oct 13 '22 14:10

Leon