我有一个像这样的 UIButton:
UIButton *inviteButton = [UIButton buttonWithType:UIButtonTypeSystem];
[inviteButton setTitle:@"Invite" forState:UIControlStateNormal];
[inviteButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:(14.0)]];
[inviteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
如何获取它的高度和宽度以便我可以设置它的框架?
如果我这样做:
float width = inviteButton.frame.size.width;
那么宽度总是为零。
我希望按钮在我创建的 View 中右对齐。
最佳答案
您必须像这样使用框架为 UIButton 设置高度和宽度。
inviteButton.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)
关于ios - 获取 UIButton 的大小并右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24338383/