按钮是的setTitle不工作/不可见 [英] Button setTitle is not working/ is not visible
本文介绍了按钮是的setTitle不工作/不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的按钮一个简单的问题。标题是不可见的。我的code是:
的UIButton *按钮= [UIButton的buttonWithType:UIButtonTypeCustom];
[按钮setImage:[UIImage的imageNamed:[的NSString stringWithFormat:@ikonki%d.png,我] forState:UIControlStateNormal];
[按钮的setTitle:@正常forState:UIControlStateNormal];
[按钮setTitleColor:[的UIColor whiteColor] forState:UIControlStateNormal];
[按钮的setEnabled:YES]; [按钮addTarget:自我
行动:@选择(buttonHandler :)
forControlEvents:UIControlEventTouchUpInside];
button.tag = I;
button.frame = CGRectMake(10 + 77 * I,125,68,68);
[self.view addSubview:键];
解决方案
是的,它是当您使用图像正常的行为
属性。
使用 和backgroundImage
属性而不是 图片
之一,是这样的:
[按钮了setBackgroundImage:[UIImage的imageNamed:[的NSString stringWithFormat:@ikonki%d.png,我] forState:UIControlStateNormal];
更新#1:
要重新定位按钮的标题下的按钮,用这样的方式:
[按钮setTitleEdgeInsets:UIEdgeInsetsMake(0.f,0.f,-60.f,0.f)]; //对齐值的特定按钮
[按钮setClipsToBounds:假];
更新#2:
要更改标题的字体,试试这个:
[button.titleLabel并入setfont:[UIFont systemFontOfSize:34.f]]; //设置字体大小,你的愿望
I have a simple problem with my buttons. Title is not visible. My code is :
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"ikonki%d.png",i]] forState:UIControlStateNormal];
[button setTitle:@"Normal" forState:UIControlStateNormal];
[button setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal];
[button setEnabled:YES];
[button addTarget:self
action:@selector(buttonHandler:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
button.frame = CGRectMake(10. + 77. * i, 125., 68 , 68);
[self.view addSubview:button];
解决方案
yep, it is normal behaviour when you are using the image
property.
use the backgroundImage
property instead of the image
one, like this:
[button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"ikonki%d.png",i]] forState:UIControlStateNormal];
UPDATE #1:
to reposition the title of the button under the button, use this way:
[button setTitleEdgeInsets:UIEdgeInsetsMake(0.f, 0.f, -60.f, 0.f)]; // align the values for your specific button
[button setClipsToBounds:false];
UPDATE #2:
to change the font of the title, try this one:
[button.titleLabel setFont:[UIFont systemFontOfSize:34.f]]; // set the font size what you desire
这篇关于按钮是的setTitle不工作/不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文