首先滚动第三方库
#import "CarouseView.h"
#import "CarouseViewPlus.h"
#define HCWidth self.view.frame.size.width
#define HCHeigth self.view.frame.size.height
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,CarouseViewDataSource, CarouseViewDelegate>
{
// 轮播图变量,其实作为局部变量也行
CarouseView*carouseView;
CarouseViewPlus*carouseViewPlus;
// 轮播图相关的数据
NSArray*kvDataArray;
}
@property (nonatomic , strong)UICollectionView *clv;
@property (strong, nonatomic) UIView *contentView;
@property (strong, nonatomic) UIButton *popBtn;
@property (nonatomic, strong)UITableView *tbv;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[selfgundong];
[self.viewaddSubview:self.tbv];
self.title=@"服务";
self.navigationController.navigationBar.titleTextAttributes=
@{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:[UIFont systemFontOfSize:22]};
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
}
-(UITableView *)tbv{
if(!_tbv) {
_tbv = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, HCWidth, HCHeigth) style:UITableViewStylePlain];
_tbv.dataSource=self;
_tbv.delegate=self;
}
return _tbv;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return 4;
}
-(void)gundong{
UIView*nbView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,HCWidth,350)];
kvDataArray=@[@"",@"",@"",@"",@""];
// 添加轮播图1
carouseView = [[CarouseView alloc] init];
carouseView.frame = CGRectMake(0, 0, self.view.frame.size.width, 220);
carouseView.datasource = self;
carouseView.delegate = self;
[nbViewaddSubview:carouseView];
NSArray*arr =@[@"22",@"22",@"22",@"22"];
NSArray *arr1 = @[@"保险精品",@"课程精品",@"车险定制",@"关于我们"];
for(inti =0; i
UIButton*bu = [[UIButtonalloc]initWithFrame:CGRectMake(15+100*i,230,70,70)];
[busetBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
[nbViewaddSubview:bu];
UILabel*l1 = [[UILabelalloc]initWithFrame:CGRectMake(15+100*i,310,70,20)];
[l1setText:arr1[i]];
[nbViewaddSubview:l1];
}
self.tbv.tableHeaderView= nbView;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell ==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
if(indexPath.row==0) {
_tbv.rowHeight=30;
cell.textLabel.text=@"| 热销产品";
}else{
_tbv.rowHeight=150;
UIImageView *im = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
im.image= [UIImageimageNamed:@"aaaa"];
[celladdSubview:im];
}
returncell;
}
#pragma mark - 轮播图代理
- (NSInteger)countOfCellForCarouseView:(CarouseView*)carouseView
{
return kvDataArray.count;
}
- (UIView*)carouselView:(CarouseView*)carouselView cellAtIndex:(NSInteger)index
{
// 填充view,可以是任意view
UIImage*image = [UIImageimageNamed:[NSStringstringWithFormat:@"%ld.jpg", (long)index +1]];
UIImageView*imageView = [[UIImageViewalloc]initWithImage:image];
UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(50,50,100,50)];
label.text=kvDataArray[index];
[imageViewaddSubview:label];
returnimageView;
}
- (void)carouseView:(CarouseView*)carouseView didSelectedAtIndex:(NSInteger)index
{
UIAlertView*alertView = [[UIAlertViewalloc]initWithTitle:@"carouse1 msg"
message:kvDataArray[index]
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil,nil];
[alertViewshow];
}
@end
网友评论