获取button上文字的宽度

来源:互联网 发布:简历注意事项 知乎 编辑:程序博客网 时间:2024/05/17 22:12

    

    NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:17]};

//获取button上文字

    NSString *title=[_buttoningtitleForState:UIControlStateNormal];

    NSLog(@"button上文字%@",title);

//获取button上文字的宽度(length 是个定义的一个全局变量)

   length = [title boundingRectWithSize:CGSizeMake(3202000)options:NSStringDrawingUsesLineFragmentOriginattributes:attributes context:nil].size.width;

//白色动画 线

    UIView *redLine =[[UIViewalloc]initWithFrame:CGRectMake(((K_SCERRN_WIDTH / 2)-length)/20,length1)];

    [redLine setBackgroundColor:[UIColor whiteColor]];

    self.arrowView = redLine;

    [_line addSubview:redLine];



button事件

[UIView animateWithDuration:0.25 animations:^{

        _arrowView.x = ((K_SCERRN_WIDTH / 2)-length)/2;

    }];



[UIView animateWithDuration:0.25 animations:^{

        _arrowView.x = _buttonend.x+((K_SCERRN_WIDTH / 2)-length)/2;

    }];


0 0
原创粉丝点击