zoukankan      html  css  js  c++  java
  • iOS Coding项目片段记录(一)

    根据UIbutton中lable状态的不同显示不同的字体颜色
    效果如图:


    #import
    <UIKit/UIKit.h> #define RGB(r,g,b) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0f] #define DefaultTextNomalColor RGB(167,160,160) #define DefaultTextSelectedColor [UIColor colorWithPatternImage:[UIImage imageNamed:[FUserInfo shareSingleton].navibar_bg_image]] @interface UIButton (richText) + (NSMutableAttributedString*)titleRichInfoStr:(NSString *)strInfo normalRange:(NSRange)normalRange normalColor:(UIColor *)normalColor selectedRange:(NSRange)selectedRange selectedColor:(UIColor *)selectedColor; + (void)allButtonShowStrInfoButton:(UIButton *)button infoStr:(NSString *)str; + (void)unReadButtonShowStrInfoButton:(UIButton *)button infoStr:(NSString *)str; + (void)trashButtonShowStrInfoButton:(UIButton *)button infoStr:(NSString *)str; @end
    #import "UIButton+richText.h"
    
    @implementation UIButton (richText)
    //根据长度来设置不同文字显示的颜色 样式
    + (NSMutableAttributedString*)titleRichInfoStr:(NSString *)strInfo normalRange:(NSRange)normalRange normalColor:(UIColor *)normalColor selectedRange:(NSRange)selectedRange  selectedColor:(UIColor *)selectedColor  {
    
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:strInfo];
    
        [AttributedStr addAttribute:NSForegroundColorAttributeName
    
                              value:normalColor
    
                              range:normalRange];
        [AttributedStr addAttribute:NSForegroundColorAttributeName
    
                              value:selectedColor
    
                              range:selectedRange];
        
        return AttributedStr;
    }
    + (void)allButtonShowStrInfoButton:(UIButton *)button infoStr:(NSString *)str{
        NSMutableAttributedString *allNormalStr = [self titleRichInfoStr:str normalRange:NSMakeRange(0, 2) normalColor:DefaultTextNomalColor selectedRange:NSMakeRange(2, str.length-2) selectedColor:DefaultTextNomalColor];
        NSMutableAttributedString *allSelectStr = [self titleRichInfoStr:str normalRange:NSMakeRange(0, 2) normalColor:DefaultTextSelectedColor selectedRange:NSMakeRange(2, str.length-2) selectedColor:DefaultTextNomalColor];
        [button setAttributedTitle:allNormalStr forState:UIControlStateNormal];
        [button setAttributedTitle:allSelectStr forState:UIControlStateSelected];
    }
    + (void)unReadButtonShowStrInfoButton:(UIButton *)button infoStr:(NSString *)str {
        NSMutableAttributedString *AttributedStr = [self titleRichInfoStr:str normalRange:NSMakeRange(0, 2) normalColor:DefaultTextNomalColor selectedRange:NSMakeRange(2, str.length-2) selectedColor:[UIColor redColor]];
        NSMutableAttributedString *AttributedSeletedStr = [self titleRichInfoStr:str normalRange:NSMakeRange(0, 2) normalColor:DefaultTextSelectedColor selectedRange:NSMakeRange(2, str.length-2) selectedColor:[UIColor redColor]];
    
        [button setAttributedTitle:AttributedStr forState:UIControlStateNormal];
        [button setAttributedTitle:AttributedSeletedStr forState:UIControlStateSelected];
    }
    + (void)trashButtonShowStrInfoButton:(UIButton *)button infoStr:(NSString *)str {
        NSMutableAttributedString *trashNormalStr = [self titleRichInfoStr:str normalRange:NSMakeRange(0, 3) normalColor:DefaultTextNomalColor selectedRange:NSMakeRange(3, str.length-3) selectedColor:DefaultTextNomalColor];
        NSMutableAttributedString *trashSelectStr = [self titleRichInfoStr:str normalRange:NSMakeRange(0, 3) normalColor:DefaultTextSelectedColor selectedRange:NSMakeRange(3, str.length-3) selectedColor:DefaultTextNomalColor];
        [button setAttributedTitle:trashNormalStr forState:UIControlStateNormal];
        [button setAttributedTitle:trashSelectStr forState:UIControlStateSelected];
    }
    @end
  • 相关阅读:
    记录log中的16进制和ASCII码字符输出
    有效的沟通技巧
    时间的真谛
    目标设定与时间管理
    第四代时间管理
    什么是高效沟通
    error LNK1104: cannot open file 错误解决方案
    js压缩工具1.0界面绘制
    时间管理的定义与目的
    JArgs命令行选项解析>Java套件
  • 原文地址:https://www.cnblogs.com/741162830qq/p/6030614.html
Copyright © 2011-2022 走看看