xcode怎么创建按钮!!我做了但是没有成功

xcode怎么创建按钮!!我做了但是没有成功,第1张

你指用 IB 还是纯代码?

代码的话,创建用:

UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0,0,200,80)]]

0,0,200,80自己改合适位置。

vc 里显示用:

[self.view addSubview:button]

响应的话:

[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]

buttonClicked 函数记得要写。

第一步:选择UnityAppController.mm这个文件打开。

并在int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight, int* openglesVersion)

这个方法里面的

return true之前加入

//创建一个全屏幕的window

CGRect rect=CGRectMake(0, 0, *screenWidth, *screenHeight)

*window=[[UIWindow alloc] initWithFrame:rect]

[*window makeKeyAndVisible]

GLView * view=[[GLView alloc] initWithFrame:rect]

[*window addSubview:view]

[view release]

MyViewController *myView=[[MyViewController alloc] init]

[*window addSubview:myView.view]

[myView release]

其中:MyViewController是导出工程后,手动新建的类,目的是,在这个ViewController种控制u3d模型的旋转、移动等动作。

第二步:创建MyViewController并添加按钮,启动u3d

- (void)viewDidLoad {

[super viewDidLoad]

//创建label视图

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]

//设置显示内容

label.text = @"雨松MOMO的程序世界"

//设置背景颜色

label.backgroundColor = [UIColor blueColor]

//设置文字颜色

label.textColor = [UIColor whiteColor]

//设置显示位置居中

label.textAlignment = UITextAlignmentCenter

//设置字体大小

label.font = [UIFont fontWithName:[[UIFont familyNames] objectAtIndex:10] size:20]

//创建按钮

UIButton *button0 = [UIButton buttonWithType:1]

//设置按钮范围

button0.frame = CGRectMake(0, 40, 100, 30)

//设置按钮显示内容

[button0 setTitle:@"矩形左旋转" forState:UIControlStateNormal]

//设置按钮改变后 绑定响应方法

[button0 addTarget:self action:@selector(LeftButtonPressed) forControlEvents:UIControlEventTouchUpInside]

//创建按钮

UIButton *button1 = [UIButton buttonWithType:1]

//设置按钮范围

button1.frame = CGRectMake(0, 100, 100, 30)

//设置按钮显示内容

[button1 setTitle:@"矩形右旋转" forState:UIControlStateNormal]

//设置按钮改变后 绑定响应方法

[button1 addTarget:self action:@selector(RightButtonPressed) forControlEvents:UIControlEventTouchUpInside]


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11355974.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存