我希望按钮文本出现在按钮中间附近,在 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];