Ios 如何设置矩形按钮的标题?

Ios 如何设置矩形按钮的标题?,ios,objective-c,uibutton,Ios,Objective C,Uibutton,您好,我是iOS开发新手,我正在尝试创建矩形UIButton,但按钮标题不可见。下面是我的代码。。。任何人都可以帮我这个密码有什么问题。。。先谢谢你 _locationBtn = [UIButton buttonWithType:UIButtonTypeCustom]; CALayer *layer = [_locationBtn layer]; //[layer setMasksToBounds:YES]; [layer setCornerRadius:0.0]; [layer setBord

您好,我是iOS开发新手,我正在尝试创建矩形UIButton,但按钮标题不可见。下面是我的代码。。。任何人都可以帮我这个密码有什么问题。。。先谢谢你

_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];
因此,解决方案:
问题似乎与按钮标题颜色有关(我认为它与背景颜色相同)。
因此,通过设置不同的标题颜色(
aColor
):

[_locationBtn setTitleColor:aColor forState:UIControlStateNormal]

尝试设置按钮标题的颜色:
[\u locationBtn setTitleColor:aColor for state:UIControlStateNormal]
,谢谢。。。。。它是有效的。。。