我希望按钮文本出现在x维度的按钮中间附近。然而,按钮文本仍然保留在视图的最左边,就好像x是0一样。我已经向setTitleEdgeInsets和setContentHorizontalAlignment确认了。我还尝试设置contentEdgeInsets而不是titleEdgeInsets。我错过了什么?
UIButton *row = [[UIButton alloc] initWithFrame:
CGRectMake(0, index * kRowHeight, 320, kRowHeight)];
[row setTitle:value forState:UIControlStateNormal];
[row setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[row setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[row setTitleEdgeInsets:UIEdgeInsetsMake(180.0, 20.0, 0, 0)];
[self.view addSubview:row];发布于 2013-07-27 04:51:50
我的参数排序不正确。
UIEdgeInsets定义为
typedef struct {
CGFloat top, left, bottom, right;
} UIEdgeInsets;发布于 2013-07-27 04:38:19
该按钮具有titleLabel属性。更改文本对齐方式。
发布于 2013-07-27 04:37:14
你有没有尝试过edgeInsets 20 20 20?
https://stackoverflow.com/questions/17890519
复制相似问题