ios CCUIHilightedLabel.m

objectivec 复制代码
//
//  CCUIHilightedLabel.h
//  CCFC
//
//


#import <UIKit/UIKit.h>


@class CCUIHilightedLabel;


@protocol UIHilightedLabelDelegate


- (void)onHilightedLabelTouchedBegan:(CCUIHilightedLabel *)hilightedLabel;


@end




// a kind of UILabel that can be touched to hilighted
@interface CCUIHilightedLabel : UILabel 
{
        id              _delegate;
        BOOL            _isHilighted;
        BOOL            _disableHilight;
    UIColor         *_hilightedColor;
}


@property(nonatomic, assign)    id              delegate;
@property(nonatomic, assign)    BOOL    isHilighted;
@property(nonatomic, assign)    BOOL    disableHilight;
@property(nonatomic, retain)    UIColor *hilightedColor;


- (id)initWithFrame:(CGRect)frame;
- (void)setIsHilighted:(BOOL)isHighlighted;


@end
objectivec 复制代码
//
//  CCUIHilightedLabel.m
//  CCFC
//
//


#import "CCUIHilightedLabel.h"




@implementation CCUIHilightedLabel


@synthesize isHilighted     = _isHilighted;
@synthesize disableHilight  = _disableHilight;
@synthesize delegate        = _delegate;
@synthesize hilightedColor  = _hilightedColor;


- (id)initWithFrame:(CGRect)frame 
{
    
    self = [super initWithFrame:frame];
    if (self)
    {
        
    }
    return self;
}


- (void)dealloc 
{
    [super dealloc];
}




- (void)setIsHilighted:(BOOL)isHighlighted
{
        if(isHighlighted)
        {
                _isHilighted = TRUE;
                super.textColor = _hilightedColor;
        }
        else
        {
                _isHilighted = FALSE;
                super.textColor = [UIColor blackColor];
        }
}




- (void)drawRect:(CGRect)rect 
{
        [super drawRect:rect];
}




- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
        if(!_disableHilight)
        {
                _isHilighted = TRUE;
                super.textColor = _hilightedColor;
                [_delegate onHilightedLabelTouchedBegan:self];
        }
}


@end

微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。

我是程序员小迷(致力于C、C++、Java、Kotlin、Android、iOS、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。

欢迎关注。助您在编程路上越走越好!

相关推荐
智算菩萨3 分钟前
【Python自然语言处理】基于NLTK库的英文文本词频统计系统实现原理及应用
开发语言·python·自然语言处理
superman超哥6 分钟前
Rust 异步并发核心:tokio::spawn 与任务派发机制深度解析
开发语言·rust·编程语言·rust异步并发核心·rust任务派发机制
喵星人工作室6 分钟前
C++传说:神明之剑0.2.1
开发语言·c++·游戏
黎雁·泠崖7 分钟前
Java入门之吃透基础语法:注释+关键字+字面量+变量全解析
java·开发语言·intellij-idea·intellij idea
Ashley_Amanda10 分钟前
Python 常见问题梳理
开发语言·windows·python
UpgradeLink13 分钟前
基于 Go 打造的升级链路管理平台:upgradelink 让设备升级更简单
开发语言·后端·golang
天府之绝14 分钟前
uniapp 中使用uview表单验证时,自定义扩展的表单,在改变时无法触发表单验证处理;
开发语言·前端·javascript·vue.js·uni-app
2501_9151063223 分钟前
常见 iOS 抓包工具的使用方式与组合思路
android·ios·小程序·https·uni-app·iphone·webview
萧鼎24 分钟前
深入解析 Python 的 Word 模板引擎:docxtpl 全面指南
开发语言·python·word
Chan1626 分钟前
场景题:如何设计一个分布式ID
java·开发语言·spring boot·java-ee·intellij-idea