UIButton文字位置显示

来源:互联网 发布:js分页代码 编辑:程序博客网 时间:2024/06/05 07:08

按钮的文字居右

UIButton *rightButton = [[UIButtonalloc] initWithFrame:CGRectMake(rightButtonX,0,rightButtonW , frame.size.height)];

//如果紧紧设置以下代码,不会生效

rightButton.titleLabel.textAlignment =NSTextAlignmentRight;

//需要加上这边这一行

rightButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;

//如果不想让文字紧贴着边框,就加上下一行

rightButton.contentEdgeInsets = UIEdgeInsetsMake(0,0, 0, 10);


文字和图片的位置调换

CGRect rightButtonFrame = self.rightButton.frame;

 self.rightButton.titleEdgeInsets =UIEdgeInsetsMake(0,0, 0,15);

 self.rightButton.imageEdgeInsets =UIEdgeInsetsMake(0, rightButtonFrame.size.width -10, 0,0);



0 0
原创粉丝点击