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等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。

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

相关推荐
豆浆whisky16 分钟前
Go并发模式选择指南:找到最适合你项目的并发方案|Go语言进阶(19)
开发语言·后端·golang
草莓熊Lotso18 分钟前
《算法闯关指南:动态规划算法--斐波拉契数列模型》--01.第N个泰波拉契数,02.三步问题
开发语言·c++·经验分享·笔记·其他·算法·动态规划
胖咕噜的稞达鸭1 小时前
自定义shell命令行解释器自制
java·开发语言
草莓熊Lotso1 小时前
Git 分支管理:从基础操作到协作流程(本地篇)
大数据·服务器·开发语言·c++·人工智能·git·sql
报错小能手1 小时前
C++异常处理 终极及总结
开发语言·c++
tobebetter95277 小时前
How to manage python versions on windows
开发语言·windows·python
9***P3348 小时前
PHP代码覆盖率
开发语言·php·代码覆盖率
CoderYanger8 小时前
优选算法-栈:67.基本计算器Ⅱ
java·开发语言·算法·leetcode·职场和发展·1024程序员节
jllllyuz8 小时前
Matlab实现基于Matrix Pencil算法实现声源信号角度和时间估计
开发语言·算法·matlab
多多*8 小时前
Java复习 操作系统原理 计算机网络相关 2025年11月23日
java·开发语言·网络·算法·spring·microsoft·maven