UIButton *movableButton = [[UIButton alloc] init];
movableButton.frame = CGRectMake(SCREEN_WIDTH-100, 160, 90, 30);
[movableButton addTarget:self action:@selector(goPlist) forControlEvents:UIControlEventTouchUpInside];
[movableButton setBackgroundColor:[UIColor colorWithHexString:@"#C00023"]];
[movableButton setImage:[UIImage imageNamed:@"icon_screen"] forState:UIControlStateNormal];
[movableButton setTitle:@"FILTER" forState:UIControlStateNormal];
[movableButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[movableButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
movableButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
//设置button图片的偏移量,距(top, left, bottom, right)的像素点为(5, 10, 5, 60)
movableButton.imageEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 60);
//设置button标题的偏移量,这个偏移量是相对于图片的
movableButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[self.view addSubview:movableButton];
IOS开发-设置UIButton 图片在左 文字在右
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 自定义 HQCustomButton 继承自 UIButton,重写layoutSubviews方法(见如下代码)...
- 各位码友, 想必大家在项目中都会遇到这种场景, UI设计师设计一个按钮,非要同时有图片及文字,而且位置不一, 看到...