1.启动页
在完成启动页的时候,要用到计时器这个东西,对计时器设定时间,在时间截止时添加事件,让其跳转到下一界面。 NSTimer用法:
NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timeOut) userInfo:nil repeats:NO];
在timeOut里添加事件函数即可。
2.自定义cell
学会自定义cell是整个网易云任务的精华所在,自定义cell不仅可以解决cell的复用问题,还可以使demo代码量减少,写起来更方便,关于自定义cell: iOS——自定义cell
没有自定义cell时遇到的复用问题:
3.按钮控制滚动视图
当按钮点击时,给按钮添加点击事件,让其控制滚动视图切换,同时控制按钮文字颜色的改变:
- (void)firstpress: (UIScrollView * )scrollView{
self.scrollView.contentOffset = CGPointMake(430 * 0, 0);
[_leftbutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[_rightbutton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}
- (void)secondpress: (UIScrollView * )scrollView{
self.scrollView.contentOffset = CGPointMake(430 * 1, 0);
[_leftbutton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[_rightbutton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
4.分栏控制器和导航栏控制器图标大小设定
在给分栏控制器和导航栏控制器的按钮添加图片时,可能大小会出现问题,例如:
或者是添加位置不在两边:
对于这个问题有两种解决方法,一种是在编译器外就把图片大小调整到合适大小,还有一种是通过一个view,调整好它的frame大小,将button添加到view上,然后再给button添加image,最后在将button赋值给UIBarButtonItem,代码如下:
UIImage *yunduoImage = [[UIImage imageNamed:@"7.jpg"]imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 40, 40);
[button setBackgroundImage:yunduoImage forState:UIControlStateNormal];
button.tintColor = [UIColor whiteColor];
UIView *leftview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[leftview addSubview:button];
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:leftview];
self.navigationItem.leftBarButtonItem = menuButton;
[button addTarget:self action:@selector(PressLeft) forControlEvents:UIControlEventTouchUpInside];
而对于下方的分栏控制器图标大小,最简洁的方法也是在编译器外就调整好大小,还有一个属性可以调整图标位置偏移量和大小,建议不要通过此方法去调整图标大小,因为参数不好控制。
tabBarItem.imageInsets = UIEdgeInsetsMake(1, 27, 1, 27);
5.换头像
换头像操作要用到协议传值,将头像设置成一个button,在点击头像的时候跳转到下一页面,然后在下一界面中添加好要传值的图片,每个图片都是一个button,当点击button的时候,将这个button里的image的名称通过字符串的方式传递到上一页面,然后在上一页面更新图片的字符串名称即可。
参考阅读
发表评论