zoukankan      html  css  js  c++  java
  • UILabel描边

    头文件

    #import <UIKit/UIKit.h>
    
    @interface UIStrokeLabel:UILabel 
    
    - (void)setStrokeColor:(UIColor*)strokeColor  (CGFloat)width;
    
    @end

    实现文件

    #import "UIStrokeLabel.h"
    
    @interface UIStrokeLabel ()
    {
        UIColor *strokeColor_;
    
        CGFloat  strokeWidth_;
    }
    @end
    
    @implementation UIStrokeLabel 
    
    #pragma mark - initlize
    
    - (id)init
    {
        if(self= [super init]){
            strokeColor_ = [[UIColor whiteColor] retain];
            strokeWidth_ = 1.0f;
        }
        return self;
    }
    
    - (id)initWithFrame:(CGRect)frame
    {
        if(self= [super initWithFrame:frame]){
            strokeColor_ = [[UIColor whiteColor] retain];
            strokeWidth_ = 1.0f;
        }
        return self;
    
    }
    
    - (id)initWithCoder:(NSCoder*)aDecoder
    {
        if(self= [super initWithCoder:aDecoder]){
            strokeColor_= [[UIColorwhiteColor] retain];
            strokeWidth_= 1.0f;
        }
        return self;
    }
    
    #pragma mark - stroke
    - (void)setStrokeColor:(UIColor*)strokeColor (CGFloat)width
    {
        [strokeColor_ release];
        strokeColor_ = nil;
        strokeColor_ = [strokeColor retain];
        strokeWidth_ = width;
    
        [self setNeedsDisplay];
    }
    
    
    - (void)drawTextInRect:(CGRect)rect
    {
        CGSize  shadowOffset = self.shadowOffset;
        UIColor* textColor = self.textColor;
    
        CGContextRefcontext = UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, strokeWidth_);
        CGContextSetLineJoin(context, kCGLineJoinRound);
    
        CGContextSetTextDrawingMode(context, kCGTextStroke);
        self.textColor = strokeColor_;
    
        [super drawTextInRect:rect];
    
        CGContextSetTextDrawingMode(context, kCGTextFill);
        self.textColor = textColor;
        self.shadowOffset = CGSizeMake(0.0f, 0.0f);
        [super drawTextInRect:rect];
    
        self.shadowOffset= shadowOffset;
    }
    
    - (void)dealloc
    {
        [strokeColor_ release]; 
        [super dealloc];
    }
    
    @end
  • 相关阅读:
    python3获取文件夹大小
    git master分支被污染,dev是最新稳定的
    优化经验杂记
    kong
    prometheus
    C# 线程执行带参方法的几种写法(ThreadStart,delegate (),()=>)
    MySql字符集utf8mb4和utf8区别
    程序员必备的一些数学基础知识
    hbase统计表的行数的三种方法
    Flink实时计算pv、uv的几种方法
  • 原文地址:https://www.cnblogs.com/SkyPrayer/p/2645048.html
Copyright © 2011-2022 走看看