UIButton의 너비를 왼쪽으로 만 사용하는 방법을 알고 싶습니다. 왼쪽으로 확장하는 앱 스토어 버튼과 거의 같습니다. 그러나 나는 여러 버튼을 사용합니다.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];
}
];
}
당신은 이전의 폭과 새로운 폭의 차이를 필요
감사 @beryllium, 오른쪽에서 왼쪽으로 코드를 소비하지만, text.width가 작을 때 다시 크기가 조정되지 않습니다. 코드가 나를 이해하는 데 어떻게 도움이되는지 설명해 주시겠습니까? – Desmond
그냥 새 프레임을 설정했습니다. [buttonCaption setFrame : ... – beryllium
새 프레임을 다시 크기를 설정 하시겠습니까? 난 여기에서 값을 가지고 5 다른 문자열 크기가 CGSize stringsize = [tempCaption sizeWithFont : [UIFont systemFontOfSize : 20]]; 일부는 다른 것보다 길 수도 있으므로 동적으로 크기를 조정해야합니다. – Desmond