0

我希望按钮文本出现在按钮中间附近,在 x 维度上。x然而,按钮文本仍然保留在视图的最左侧,就像0. 我已经确定setTitleEdgeInsetssetContentHorizontalAlignment。我还尝试设置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];
4

4 回答 4

2

我错误地订购了参数。

UIEdgeInsets被定义为

typedef struct {
   CGFloat top, left, bottom, right;
} UIEdgeInsets;
于 2013-07-26T20:51:49.910 回答
1

该按钮有一个titleLabel属性。更改其上的文本对齐方式。

于 2013-07-26T20:38:18.660 回答
0

嗨,为 Inset Button 添加此代码

extension UIButton {
    /**
        Creates an edge inset for a button
        :param: top CGFLoat
        :param: left CGFLoat
        :param: bottom CGFLoat
        :param: right CGFLoat
    */
    func setInset(#top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) {
           self.titleEdgeInsets =  UIEdgeInsetsMake(top, left, bottom, right)
    }
}
于 2015-01-15T14:56:20.683 回答
0

您是否尝试过 edgeInsets 20 20 20 20 ?

于 2013-07-26T20:37:13.600 回答