ios - 用户界面按钮 : How to set image and text using imageEdgeInsets and titleEdgeInsets?

标签 ios iphone objective-c uiedgeinsets

我有一个应用程序,其中使用 UIButton 以及 titleUIImage。他们的对齐似乎是第一个标题,然后是UIImage

我试过这个:

[dropdownbutton setImage: [UIImage imageNamed:@"down_sml_arrow.png"] 
                                     forState:UIControlStateNormal];
CGFloat spacing = 10; // the amount of spacing to appear between image and title
dropdownbutton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, spacing);
dropdownbutton.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
[dropdownbutton setTitle:@"Your text" forState:UIControlStateNormal];

但是这里UIImage出现在标题之前。有人能指出我哪里出错了吗?

最佳答案

替代

UIImageView *imageView1=[[UIImageView alloc]init];
UIButton *dropdownbutton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
dropdownbutton.frame=CGRectMake(50, 50, 120, 50);
imageView1.image=[UIImage imageNamed:@"arrows.png"];
imageView1.frame=CGRectMake(85, 12, 25, 25);
dropdownbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[dropdownbutton addSubview:imageView1];
CGFloat spacing = 10; // the amount of spacing to appear between image and title
dropdownbutton.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
[dropdownbutton setTitle:@"Your text" forState:UIControlStateNormal];
[self.view addSubview:dropdownbutton];

关于ios - 用户界面按钮 : How to set image and text using imageEdgeInsets and titleEdgeInsets?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212531/

相关文章:

objective-c - 如何向 UIBarButtonItem 添加图像?

ios - 请在 Apple SpriteKit 示例代码中解释 uint32_t 和 0x1 << 0

iphone - 强制后台应用程序在 iOS 模拟器中终止

iphone - 单位 : Establishing WebSocket Connection

ios - 如何使用 ios-charts 制作分组条形图?

ios - AFNetworking 2.0并授权Imgur API

ios - UICollectionViewCell 消息在出队后立即发送到已释放的实例

iphone - 核心数据 : setPrimitiveValue and saving changes

objective-c - 如何以编程方式初始化 nib 值

objective-c - 从模态视图中删除呈现 View