zoukankan      html  css  js  c++  java
  • NSButton文本颜色设置和Action两种状态行为

    //获取文本颜色:

    - (NSColor *)textColor

    {

        NSAttributedString *attrTitle = [self attributedTitle];

        int len = [attrTitle length];

        NSRange range = NSMakeRange(0, MIN(len, 1)); // get the font attributes from the first character

        NSDictionary *attrs = [attrTitle fontAttributesInRange:range];

        NSColor *textColor = [NSColor controlTextColor];

        if (attrs)

        {

            textColor = [attrs objectForKey:NSForegroundColorAttributeName];

        }

       

        return textColor;

    }

     

    //设置文本颜色

    - (void)setTextColor:(NSColor *)textColor

    {

        NSMutableAttributedString *attrTitle =

            [[NSMutableAttributedString alloc] initWithAttributedString:[self attributedTitle]];

        int len = [attrTitle length];

        NSRange range = NSMakeRange(0, len);

        [attrTitle addAttribute:NSForegroundColorAttributeName value:textColor range:range];

        [attrTitle fixAttributesInRange:range];

        [self setAttributedTitle:attrTitle];

        [attrTitle release];

    }

    //一个button两种状态行为:

    - (IBAction)pressSpaceKey:(id)sender {

      

        NSLog(@" go to record");

       

        // 需要给这个按钮增加一个事件,让它与keyDown/keyUp 关联,按住按钮时一直录音,松开按钮时录音结束。

     

        NSButton * btn = (NSButton *)sender;

        if ([btn tag] == 100) {

            btn.tag = 101;

         //添加动作代码

            [btn setTitle:@"停止录音"];

           

           

        }else if ([btn tag] == 101){

            btn.tag = 100;

        //添加另外一种状态的动作代码

            [btn setTitle:@"开始录音"];

          

        }

    }

    //单选框

    IBOutlet NSMatrix *popoverType;

     

  • 相关阅读:
    根据group by、count case when 分组分类统计
    Cron表达式
    SQL分页查询 — 不同页面的查询结果有重复数据
    Dockerfile文件语法
    redis获取系统当前时间
    mybatis oracle批量插入数据
    Mysql函数->TRIM(去掉首尾空格、任意字符)
    Oracle函数->TRIM(去掉首尾空格、首尾字符)
    使用redis-list类型 限制用户1分钟内访问次数为100次
    一文了解mysql基础架构
  • 原文地址:https://www.cnblogs.com/PJXWang/p/4921507.html
Copyright © 2011-2022 走看看