-

这样就能实现无线轮播的效果了,思路和逻辑上述,看到的伙伴多去实践操作一下

// 左右切换button
UIButton* btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton* btnRight = [UIButton buttonWithType:UIButtonTypeCustom];
btnLeft.frame = CGRectMake(0, (self.view.frame.size.height) / 2, 40, 40);
btnRight.frame = CGRectMake(self.view.frame.size.width - 50, (self.view.frame.size.height) / 2, 40, 40);
UIImage* icon1 = [UIImage imageNamed:@"UIbntL.jpeg"];
UIImage* icon2 = [UIImage imageNamed:@"UIbtnR.jpeg"];
[btnLeft setImage:icon1 forState:UIControlStateNormal];
[btnRight setImage:icon2 forState:UIControlStateNormal];
[btnLeft addTarget:self action:@selector(pressBtnLeft) forControlEvents:UIControlEventTouchUpInside];
[btnRight addTarget:self action:@selector(pressBtnRight) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnLeft]; [self.view addSubview:btnRight];;-(void) pressBtnLeft {
NSLog(@"pressBtnLeft");
int page = _scrollView.contentOffset.x / self.view.frame.size.width;
_scrollView.contentOffset = CGPointMake(self.view.frame.size.width * (page - 1), 0);
if (page == 0) {
_scrollView.contentOffset = CGPointMake(self.view.frame.size.width * 5, 0);
page = 5;
}
}
-(void) pressBtnRight {
NSLog(@"pressBtnRight");
int page = _scrollView.contentOffset.x / self.view.frame.size.width;
_scrollView.contentOffset = CGPointMake(self.view.frame.size.width * (page + 1), 0);
if (page == 7){
_scrollView.contentOffset = CGPointMake(self.view.frame.size.width * 1, 0);
}
}
这样第一个界面的需求就基本完成了

UITableViewCell* cell;
if (indexPath.row == 0) {
NSString* strId = @"Personal Page";
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strId];
}
// cell赋值
cell.textLabel.text = @"服务";
// cell附加图样式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
cell.imageView.image = [UIImage imageNamed:@"UIWechat7.jpeg"];
cell.backgroundColor = [UIColor whiteColor];

在这里插入代码 // 设置tableViewcell----图片大小的方法
CGSize itemSize = CGSizeMake(100, 100);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();片
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// 不加此句时,在二级栏目点击返回时,此行会由选中状态慢慢变成非选中状态。
// 加上此句,返回时直接就是非选中状态。
if (indexPath.row == 0) {
UIViewServe* UIViewServe1 = [[UIViewServe alloc] init];
[self.navigationController pushViewController:UIViewServe1 animated:YES];
} else if (indexPath.row == 4) {
UIViewFriends* UIViewF = [[UIViewFriends alloc]init];
[self.navigationController pushViewController:UIViewF animated:YES];
}
}