UIButton的image和title位置设置

{app.params.name}} {app.params.name}} {app.params.name}}

通过setTitle和titleEdgeInsets,setImage和imageEdgeInsets,能够实现title和image位置的变化

具体的代码我以实现title的位置变化为例子:

UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
addButton.layer.borderColor = [[UIColor whiteColor] CGColor];
addButton.layer.borderWidth = 2.0;
addButton.layer.cornerRadius = 10.0;
addButton.titleLabel.font = [UIFont systemFontOfSize:54.0];
addButton.titleLabel.textAlignment = NSTextAlignmentCenter;
[addButton sizeToFit];
[addButton setTitleEdgeInsets:UIEdgeInsetsMake(-10.0, 0.0, 0.0, 0.0)];
[addButton setFrame:CGRectMake(0.0, 5.0, 60.0, 60.0)];
[addButton setTitle:@"+" forState:UIControlStateNormal];
[addButton addTarget:self
              action:@selector(addAction:)
    forControlEvents:UIControlEventTouchUpInside];


版权声明

davidzhang 创作并维护的 Gowhich 博客采用 创作共用保留署名-非商业-禁止演绎4.0国际许可证。

本文首发于 Gowhich 博客( https://www.gowhich.com ),版权所有,侵权必究。

本文永久链接: https://www.gowhich.com/blog/193

comments powered by Disqus