我想知道如何将 UIButton 的宽度仅向左扩展,非常类似于将向左扩展的应用商店按钮。但是我有多个按钮要花费。
编辑这是工作代码:
//viewdidload
buttonCaption = [UIButton buttonWithType:UIButtonTypeCustom];
//default placement
buttonCaption.frame = CGRectMake(245, 385, 70, 30); //default width size
[self nextAnimation:buttonCaption.frame.size.width];
将默认值传递给动画
-(void)nextAnimation:(float)previousWidth {
//button setting
buttonCaption.titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin ;
//buttonCaption.titleLabel.font =[UIFont systemFontOfSize:20];
[[buttonCaption layer] setCornerRadius:5.0f];
[[buttonCaption layer] setMasksToBounds:YES];
[[buttonCaption layer] setBackgroundColor:[[UIColor colorWithRed:0 green:0 blue:0 alpha:0.7] CGColor]];
[buttonCaption.titleLabel setFrame:CGRectMake(0,0, 25, 25)];
CGSize stringsize = [tempCaption sizeWithFont:[UIFont systemFontOfSize:20]];
CGFloat diff = stringsize.width - previousWidth;
NSLog(@"diff %f",diff);
[UIView animateWithDuration:0.5
animations:^{
[buttonCaption setFrame:CGRectMake(buttonCaption.frame.origin.x-diff,
buttonCaption.frame.origin.y,
buttonCaption.frame.size.width + diff,
buttonCaption.frame.size.height)];
}
completion:^(BOOL completed)
{
[self nextAnimation:stringsize.width];
}
];
}