首页 > 学院 > 开发设计 > 正文

获取button上文字的宽度

2019-11-09 16:39:23
字体:
来源:转载
供稿:网友

    

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

//获取button上文字

    NSString *title=[_buttoningtitleForState:UIControlStateNormal];

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

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

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

//白色动画 线

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

    [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;

    }];


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表