ios - 按钮标题隐藏按钮图像iOS

标签 ios objective-c

我在按钮上同时设置标题和图像..但是我面临问题..我的按钮标题与图像重叠。

我的代码是

-(void )addImageonbtn:(UIButton *)Button{
 [Button setImage:[UIImage imageNamed:@"drop_bg"] forState:UIControlStateNormal];
Button.imageEdgeInsets = UIEdgeInsetsMake(0, Button.frame.size.width, 0, 24);
Button.titleEdgeInsets = UIEdgeInsetsMake(0, -37, 0, 0);
Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft ;

Button.layer.borderWidth=1;
Button.layer.borderColor=[UIColor colorWithRed:5/255.0 green:195/255.0 blue:249/255.0 alpha:1.0].CGColor;
Button.clipsToBounds=YES;
}

如何在图像背景中设置图像。这是问题的图像
enter image description here

最佳答案

您需要设置背景图片来解决重叠标题问题。

 [Button setBackgroundImage:[UIImage imageNamed:@"drop_bg"] forState:UIControlStateNormal];

希望这会帮助你。

关于ios - 按钮标题隐藏按钮图像iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41670097/

相关文章:

ios - react-native StackNavigator 中的条件 header

ios - UITableView - 在 vi​​ewDidAppear 之前滚动到底部

objective-c - UITableView 上的 sendSubviewToBack 在 iOS 11 中无法正常工作

objective-c - 为报亭应用制作应用内商店

ios - 使用嵌入式 View Controller 调整 UIScrollView 的 contentSize

ios - 如何使用 SDWebImage 加载 webp 图片?

iphone - selectall uitextfield 并不总是全选

objective-c - clang 的哪些编译选项改变了它们在 Objective C 和 Objective C++ 之间的默认值?

iOS/xcode/objective-c : How to instantiate view controller after signup

ios - 将 NSDictionary 中的字符串值转换为 long 使应用程序崩溃