

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;
}];
新聞熱點
疑難解答