我有一个应用程序,其中使用 UIButton
以及 title
和 UIImage
。他们的对齐
似乎是第一个标题,然后是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/