gpt4 book ai didi

ios - 我的按钮和 textview 没有显示在 iOS 的屏幕上?

转载 作者:行者123 更新时间:2023-11-28 21:55:48 27 4
gpt4 key购买 nike

我正在动态创建三个按钮和一个 uitextview,但是当我运行该程序时,它没有显示在我的屏幕上

这是我创建动态按钮和 TextView 的代码

   -(void)getSmsdisplay

{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UITextView *textview=[[UITextView alloc]init];
[button setTitle:@"Comment" forState:UIControlStateNormal];
[button1 setTitle:@"Share" forState:UIControlStateNormal];
[button1 setTitle:@"Like" forState:UIControlStateNormal];

//listen for clicks
[button addTarget:self
action:@selector(btncomment:)forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self
action:@selector(btnShare:)forControlEvents:UIControlEventTouchUpInside];

[button2 addTarget:self
action:@selector(Like:)forControlEvents:UIControlEventTouchUpInside];

smsdata *data=[[smsdata alloc]init];

[textview setText:data.Data];
[self.view addSubview:textview];



//add the button to the view
[self.view addSubview:button];
[self.view addSubview:button1];
[self.view addSubview:button2];

}

最佳答案

你的编码很好,但是你没有为 UIButtonUItextview 添加框架

-(void)getSmsdisplay

{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];


UITextView *textview=[[UITextView alloc]init];

button.frame=CGRectMake(20, 50, 200, 50);

button1.frame=CGRectMake(20, 150, 200, 50);

button2.frame=CGRectMake(20, 300, 200, 50);

button.backgroundColor=[UIColor redColor];
button1.backgroundColor=[UIColor grayColor];
button2.backgroundColor=[UIColor blackColor];

[button setTitle:@"Comment" forState:UIControlStateNormal];
[button1 setTitle:@"Share" forState:UIControlStateNormal];
[button2 setTitle:@"Like" forState:UIControlStateNormal];

//listen for clicks
[button addTarget:self
action:@selector(btncomment:)forControlEvents:UIControlEventTouchUpInside];
[button1 addTarget:self
action:@selector(btnShare:)forControlEvents:UIControlEventTouchUpInside];

[button2 addTarget:self
action:@selector(Like:)forControlEvents:UIControlEventTouchUpInside];



[textview setText:@"karthik"];
[self.view addSubview:textview];



//add the button to the view
[self.view addSubview:button];
[self.view addSubview:button1];
[self.view addSubview:button2];

}

输出是enter image description here

关于ios - 我的按钮和 textview 没有显示在 iOS 的屏幕上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26625069/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com