0

我在 Xcode 上设计一个按钮时遇到了麻烦。

我正在使用以下代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundRect];
button.frame=CGRectMake(80.0,210,160,40);
[self.view addSubview:button];

代码是构建成功。但是这个错误来了:

线程 1:EXC_BAD_ACCESS(代码=2,地址=0xbf7ffffdc)

4

2 回答 2

2

这是您可以根据所需的背景和文本颜色创建自定义按钮的方式。

 btn_fbLogin = [[UIButton alloc]initWithFrame:CGRectMake(95,254,130,41)];
[btn_fbLogin setTitle:@"FLogin" forState:UIControlStateNormal];
[btn_fbLogin addTarget:self action:@selector(FacebookLogin) forControlEvents:UIControlEventTouchUpInside];
[btn_fbLogin setBackgroundColor:[UIColor whiteColor]];
btn_fbLogin.clipsToBounds = YES;
btn_fbLogin.layer.cornerRadius = 5.0f;
[btn_fbLogin setTitleColor:[UIColor colorWithRed:244/255.0  green:185/255.0 blue:25/255.0 alpha:1.0] forState:UIControlStateNormal];
[btn_fbLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];     
[self.view addSubview:btn_fbLogin];

并且不要忘记导入#import <QuartzCore/QuartzCore.h>

希望这可以帮助..:)

于 2013-01-05T12:59:48.107 回答
0
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(80.0,210,160,40);
[button setTitle:@"Submit" forState:UIControlStateNormal];
[self.view addSubview:button];

您得到的错误似乎不是 UIButton 的原因。你能指定更多吗?

于 2013-01-05T12:56:15.657 回答