简体   繁体   English

如何设置矩形UIButton的标题?

[英]How to set title for rectangular UIButton?

hi am new to iOS development and am trying to create Rectangular UIButton But button title is not visible. 嗨,我是iOS开发的新手,正在尝试创建Rectangular UIButton,但是按钮标题不可见。 Below is my code... anybody can help me whats wrong in this code... thanks in advance... 以下是我的代码...任何人都可以帮助我解决此代码中的问题...预先感谢...

_locationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
CALayer *layer = [_locationBtn layer];
//[layer setMasksToBounds:YES];
[layer setCornerRadius:0.0];
[layer setBorderWidth:1.0];
[layer setBorderColor:[[UIColor grayColor] CGColor]];

[_locationBtn addTarget:self action:@selector(dropDownMtd) forControlEvents:UIControlEventTouchUpInside];
_locationBtn.frame = CGRectMake(20, 170, 280, 40);
[_locationBtn setTitle:@"Select location" forState:UIControlStateNormal];
[self.view addSubview:_locationBtn];

So the solution: 所以解决方案:
The issue seems to be with the button title color (which I presume was the same color as its background). 问题似乎出在按钮标题的颜色上(我认为与背景颜色相同)。
So, by setting the title color ( aColor ) different: 因此,通过设置不同的标题颜色( aColor ):

[_locationBtn setTitleColor:aColor forState:UIControlStateNormal]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM