UIEdgeInset问题定位文本/图像 [英] UIEdgeInset issue positioning text/image
本文介绍了UIEdgeInset问题定位文本/图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试制作一个 UIButton
,图片高于文字,所以我使用这段代码:
I try to make an UIButton
with image upper the text, so I use this code:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(x, y, 140, 140);
[btn setTitle:self.objMateria.titoloMateria forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor clearColor]];
[btn setImage:[UIImage imageNamed:@"pala.png"] forState:UIControlStateNormal];
btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 20, 0);
btn.titleEdgeInsets = UIEdgeInsetsMake(120, 0, 0, 0);
问题在于,使用此代码我看不到文本,这似乎是由图片,哪里出错?
the problem is that with this code I don't see the text, that seems to be covered by the image, where is the mistake?
这里图片:
here the image:
推荐答案
试试这个
btn.imageEdgeInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
btn.titleEdgeInsets = UIEdgeInsetsMake(120, -120, 0, 0);
调整 -120
的值,即 left 横向调整你的标题
Adjust the value of -120
i.e. left to horizontally fit your title
这篇关于UIEdgeInset问题定位文本/图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文