Iphone 请求非结构或联合中的成员视图?

Iphone 请求非结构或联合中的成员视图?,iphone,Iphone,如果您是在UIView的子类类中编写的 你应该试试 UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]; playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0); [playButton setTitle:@"Play" forState:UIControlStateNormal]; playButton.backgroundColor = [

如果您是在UIView的子类类中编写的

你应该试试

UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect];
playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[playButton setTitle:@"Play" forState:UIControlStateNormal];
playButton.backgroundColor = [UIColor clearColor];
[playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
**//[self.view addSubview:playButton];**

首先创建视图

[self addSubview:playButton];
然后像这样将此按钮添加到此视图

UIView *myview=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];   
[self.view addSubview:myview];  

试试这个。。如果它不工作,请与我通信…

它在注释行中显示错误,您将代码放在哪里?当前类的类型是什么?实际上,我想创建一个不带out的按钮。第一行中的括号不匹配。请更正这一行:-UIButton*playButton=[UIButton buttonwhithtype:uibuttontyperoundrect];嘿,我试过了,但它显示了一些警告,比如委托可能不会响应AddSubViews,您在哪个类中编写此代码。类的类型是什么?我在实现类中执行此操作#import@interface UntitledAppDelegate:NSObject{UIWindow*window;@property(非原子,保留)UIWindow*window;@end您正在应用程序委托中执行此操作。然后尝试
[self.window addSubview:button];
如果
[self.view addSubview:button];
显示错误如何才能
[self.view addSubview:myview];
不显示它?
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
           action:@selector(aMethod:)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[myview addSubview:button];