ScrowView具体用法
//UIView:
-(id)initWithFrame:(CGRect)frame id)target SEL)sel
{
self=[super initWithFrame:frame];
if (self)
{
controller=target; //传一个id类型的controller
[self creatScrow];
f_tableA=[self creatTableA]; //f_ 表示设置为全局变量
f_tableB=[self creatTableB];
}
return self;
}
-(void)creatScrow
{
scrow=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 30, self.frame.size.width, self.frame.size.height-50)];
scrow.directionalLockEnabled=YES;//只能一个方向滑动
scrow.pagingEnabled = YES; //是否翻页
scrow.backgroundColor = [UIColor blackColor];
scrow.showsVerticalScrollIndicator =NO; //垂直方向的滚动指示
scrow.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
scrow.showsHorizontalScrollIndicator = YES;//水平方向的滚动指示
CGSize size=CGSizeMake(self.frame.size.width * 2, 0);
[scrow setContentSize:size];
[self addSubview:scrow];
[self creatTableA];
[self creatTableB];
}
-(id)creatTableA
{
UITableView *tableA=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.frame.size.height) style:UITableViewStylePlain];
tableA.delegate=controller;//设置代理方法
tableA.dataSource=controller;
tableA.backgroundColor = [UIColor blueColor];
[scrow addSubview:tableA];
return tableA;
}
-(id)creatTableB
{
UITableView *tableB=[[UITableView alloc]initWithFrame:CGRectMake(self.frame.size.width, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain];
tableB.delegate=controller;//设置代理方法
tableB.dataSource=controller;
tableB.backgroundColor = [UIColor greenColor];
[scrow addSubview:tableB];
return tableB;
}
//UIViewController:
//在代理方法中的写法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==scrowView.f_tableA)
{
}
if (tableView==scrowView.f_tableB)
{
}
}
猜你喜欢
转载自cydd.iteye.com/blog/2171097
今日推荐
周排行