简体   繁体   English

ios-在另一个UIView中将UIView子类化?

[英]ios - Subclassing an UIView inside another UIView?

I have 2 UIViews both with a bit off code in them. 我有2个UIViews,其中都有一些代码。

I can subclass one to a UIViewController like this self.view addSubView:_msgView]; 我可以将一个子类self.view addSubView:_msgView];给UIViewController,例如self.view addSubView:_msgView]; _msgView being a UIView. _msgView是UIView。

Now _msgView is a Plain UIView that has a 0.7 Alpha to lay over the UIViewController. 现在,_msgView是一个普通的UIView,它具有0.7 Alpha放在UIViewController上。

now I have another UIView called menuButtons and I want to put that on top of the _msgView. 现在我有另一个UIView叫做menuButtons,我想把它放在_msgView的顶部。

I was thinking I could use [_msgView addSubView:_menuButton]; 我以为我可以使用[_msgView addSubView:_menuButton]; but that does not work and gives a warning 但这不起作用并且发出警告

Incompatible pointer types sending 'MenuButtons *__strong' to parameter of type 'UIView *' 不兼容的指针类型将“ MenuButtons * __ strong”发送到“ UIView *”类型的参数

How do I put a UIView on top of another UIView? 如何将一个UIView放在另一个UIView之上?

//EDITS: //编辑:

#import <UIKit/UIKit.h>
#import "SlideMessageView.h"
#import "definitions.h"


@interface MenuButtons : UIView
{
UIButton *onBack;
UIButton *onForward;
UIButton *onRefresh;
UIButton *onHome;
UIButton *onSafari;
UIButton *onChrome;
UIButton *onPocketReader;
UIButton *onSavePDF;
UIButton *onPrint;
UIButton *onShare;

SlideMessageView *msgView;

BOOL viewVisible;
}

The UIButtons have their @properties set below that. UIButton在其下方设置了@properties。

you do 1 thing.. if u are generating both the views through code then add both views in self.view itself and set their frames separately. 您做1件事..如果您通过代码生成两个视图,则将两个视图添加到self.view本身中并分别设置其框架。

ie if 1st view is at top set the frame msgview.frame = CGRectMake(0,0,320,100); 即,如果第一个视图位于顶部,则设置框架msgview.frame = CGRectMake(0,0,320,100); ans for second view someview.frame = CGRectMake(0,100,320,200); 第二个视图的ans someview.frame = CGRectMake(0,100,320,200);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM