如图,我们要实现一个 左边图标右边文本的效果,一般 可以考虑是 UIImageView + UILabel
不过,其实一个UIButton就可以搞定了
代码:
UIButton *tBtn = [UIButton buttonWithType:UIButtonTypeCustom]; tBtn.frame = CGRectMake(100, 100, 70, 30); [tBtn setImage:[UIImage imageNamed:@"good_red.png"] forState:UIControlStateNormal]; [tBtn setTitle:@"11" forState:UIControlStateNormal]; // [tBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 20, 0, 20)]; [tBtn setTitleEdgeInsets:UIEdgeInsetsMake(13, 0, 0, 0)]; [tBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; [self.view addSubview:tBtn];
时间: 2024-10-11 07:27:04