2015-07-13 65 views
0

我使用的是水平scrollview一些按钮和搜索bar.I需要显示它在所有的视图控制器。这里是我的代码添加自定义滚动型水平在所有视图控制器

for (int i=0;i<[[[xmlSubDictionary objectForKey:@"pillars"]objectForKey:@"pillar"]count];i++) 
{ 
    [pillarArray addObject:[[[[[xmlSubDictionary objectForKey:@"pillars"]objectForKey:@"pillar"]objectAtIndex:i]objectForKey:@"pillarName"]objectForKey:@"text"]]; 

///// UIButton* ideaButton = [[UIButton alloc] initWithFrame:CGRectMake((i*self.scrolView.frame.size.width)/2.5, 3,  self.scrolView.frame.size.width/2.5,40)]; 
    if (i==0) 
    { 
    ideaButton.frame = CGRectMake((i*self.scrolView.frame.size.width)/2.5, 3, self.scrolView.frame.size.width/2.5, 40); 
    [self.view bringSubviewToFront:self.scrolView]; 

    [ideaButton setTitleColor:[UIColor colorWithRed:0 green:175 blue:69 alpha:1] forState:UIControlStateNormal]; 
    } 
else 
{ 
    [ideaButton setTitleColor:[UIColor colorWithRed:0.42 green:0.42 blue:0.42 alpha:1] forState:UIControlStateNormal]; 
} 
[ideaButton setTitle:[[pillarArray objectAtIndex:i] uppercaseString] forState:UIControlStateNormal]; 
[ideaButton setTag:101+i];  
[ideaButton addTarget:self action:@selector(ActionForMealButtonAction:) forControlEvents:UIControlEventTouchUpInside]; 
    ideaButton.titleLabel.font = [UIFont fontWithName:@"Akkurat-Bold" size:17.0]; 
    ideaButton.backgroundColor = [UIColor clearColor]; 
    [self.scrolView addSubview:ideaButton]; 
} 
[self.scrolView setContentSize:CGSizeMake([pillarArray count] * ((self.view.frame.size.width+200)/([pillarArray count])-5), CGRectGetHeight(self.scrolView.frame))]; 
+0

请,格式正确答案。无法读取您的代码! – webo80

+0

我应该在应用程序委托类中使用此方法吗?如果是,那我该如何使用它? – RakeshBiswal

回答

0

您可以创建一个UIView的新子类,并在其中添加您的特定代码。当分类时,您可以轻松地在所有视图控制器中使用您的视图。

UIView的文档: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/index.html

+0

点击按钮我需要调用多个服务调用多个服务调用。它需要在控制器的顶部正好放置在导航栏上。在我的应用程序中没有导航栏,只有水平滚动器包含多个按钮和搜索酒吧。 – RakeshBiswal

+0

在我的项目中,我使用了大量的子类化视图,但我尝试保留应用程序中的所有操作以执行“委托”调用。你的子类UIView应该实现委托逻辑,当单击一个按钮时,可以在视图控制器上回调,并单击了哪个按钮。 – knutigro

+0

是的...确切地说...我应该使用滚动视图xib吗? – RakeshBiswal

相关问题