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
  • 相关阅读:
    oracle重命名数据库
    GridView分页的实现
    vb发post信息,非常简单,就一个函数
    第六周进度条
    软件工程作业
    进度条第五周
    四则运算设计03
    进度条03
    单元测试课堂作业
    个人作业02
  • 原文地址:https://www.cnblogs.com/SkyPrayer/p/2645048.html
Copyright © 2011-2022 走看看