Ios5 ios:ios应用程序中不同屏幕上的相同ui控件
我对iOS开发相当陌生。我的要求是我正在设计一个包含5个屏幕的应用程序。我有一组UI控件(1个UIImageView,5个UIButtons,每个屏幕都像选项卡栏一样),这些控件对所有屏幕都是通用的。单击按钮时,只有视图的下半部分需要更改相关详细信息,而按钮保持不变(类似于windows中的选项卡控件) 有没有办法实现这种设计?我可以在多个屏幕上共享UI控件而不重复代码或Ios5 ios:ios应用程序中不同屏幕上的相同ui控件,ios5,uibutton,Ios5,Uibutton,我对iOS开发相当陌生。我的要求是我正在设计一个包含5个屏幕的应用程序。我有一组UI控件(1个UIImageView,5个UIButtons,每个屏幕都像选项卡栏一样),这些控件对所有屏幕都是通用的。单击按钮时,只有视图的下半部分需要更改相关详细信息,而按钮保持不变(类似于windows中的选项卡控件) 有没有办法实现这种设计?我可以在多个屏幕上共享UI控件而不重复代码或 有没有办法在单击按钮时仅更改屏幕的下半部分?您可以有一个单独的类来创建uicontrol,然后为每个viewcontroll
有没有办法在单击按钮时仅更改屏幕的下半部分?您可以有一个单独的类来创建uicontrol,然后为每个viewcontroller调用appropiate方法以获得所需的uicontrol
@interface UIControlMaker : NSObject{
id controlmakerDelegate; // This is so that you can send messages to the viewcontrollers
}
@property (nonatomic,retain) id controlmakerDelegate; // Release it in dealloc method
- (id)initWithDelegate:(id)delegate;
- (UIView *)createCommonUIControls;
在实现文件中
@implementation UIControlMaker
@synthesize controlmakerDelegate;
- (id)initWithDelegate:(id)delegate{
if(self = [super init]){
[self setControlMakerDelegate:delegate];
return self;
}else
return nil;
}
- (UIView *)createCommonUIControls{
UIView *uicontrolsHolder = [[UIView alloc] initWithFrame:CGRectMake(2,40,320,50)];
// Create as many uicontrols as you want. It'd be better if you have a separate class to create them
// Let's create a button for the menuItem
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0 , 0, 50, 35)];
button.backgroundColor = [UIColor clearColor];
[button setTitle:@"Button 1" forState:UIControlStateNormal];
[button addTarget:controlmakerDelegate action:@selector(buttonOnClick) forControlEvents:UIControlEventTouchUpInside];
[uicontrolsHolder addView:button];
[button release];
// Add more uicontrols here
retun [uicontrolsHolder autorelease];
}
然后在viewcontroller中创建UIControlMaker实例并调用createCommonUIControls方法,该方法将返回可添加到viewcontroller的视图。希望这是清楚的