• 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
  • 相关阅读:
    java常量和变量的定义规则,变长参数的使用
    测试一下windowsLiveWriter
    对转换公式为LaTeX代码要注意什么
    后台登陆骨架
    为什么要把session存入数据库
    登录功能测试
    数据库快速配置
    一个小bug
    后台测试常需要的htm样式
    在分页的基础上添加删除和(查看,原理和删除一样)
  • 原文地址:https://www.cnblogs.com/SkyPrayer/p/2645048.html
Copyright © 2020-2023  润新知