我知道如何用IB设置按钮的垂直对齐;看here https://stackoverflow.com/a/7538683/377384。但我不能以编程方式做到这一点......这是我尝试过的事情之一:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 110, 130)];
[button setTitle:@"Align" forState:UIControlStateNormal];
button.backgroundColor = [UIColor whiteColor];
button.titleLabel.textColor = [UIColor grayColor];
[button setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom];
[self.view addSubview:button];
[button release];
我也尝试过插入...
但对齐方式不会改变。
请注意,我想保留按钮的 CustomStyle(我不想要默认的外观和感觉)。
您可以通过以下方式对齐(水平和垂直)按钮的文本:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 70)];
button.backgroundColor = [UIColor whiteColor];
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
[button setTitle:@"Align" forState:UIControlStateNormal];
[self.container addSubview:button];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)