一,效果图。

二,工程图。

三,代码。

ReaderViewController.h

#import <UIKit/UIKit.h>

@interface ReaderViewController : UIViewController
<UIScrollViewDelegate>
{
UIScrollView *scrollView;
}
@property(nonatomic,strong) UIScrollView *scrollView;;
-(void)add;
-(void)dele;
-(void)reloadView; @end

ReaderViewController.m

#import "ReaderViewController.h"

#define ImageHeight 120
static int num = 0; @interface ReaderViewController () @end @implementation ReaderViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //字体的颜色
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:248.0/255.0 green:172.0/255.0 blue:37.0/255.0 alpha:1.0];
//导航栏背景图
[self addBackgroundView:@"1.png"]; //左侧删除按钮
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]
initWithTitle:@"delete"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(dele)];
//右侧增加按钮
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(add)]; self.navigationItem.rightBarButtonItem = rightBarButton;
self.navigationItem.leftBarButtonItem = leftBarButton; //scrollerView
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
scrollView.contentSize=CGSizeMake(320,480); //设置背景颜色
UIImage *backimg=[UIImage imageNamed:@"3.png"];
UIImageView *backview=[[UIImageView alloc] initWithImage:backimg];
backview.frame=CGRectMake(0, 0, 320, 480);
[self.view addSubview:backview]; [self.view addSubview:scrollView];
//重新刷新界面
[self reloadView]; }
//导航栏上标题
-(void)addBackgroundView:(NSString*)image{ UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:image]];
imgView.frame = CGRectMake(0, 0, 320, 44);
[self.navigationController.navigationBar addSubview: imgView]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake((320-150)/2, 0, 150, 44)];
[title setText:@"书架"];
[title setTextColor:[UIColor whiteColor]];
[title setTextAlignment:NSTextAlignmentCenter];
[title setShadowColor:[UIColor grayColor]];
[title setBackgroundColor:[UIColor clearColor]];
[title setFont:[UIFont boldSystemFontOfSize:20.0]];
[self.navigationController.navigationBar addSubview:title];
} //添加一个书架
-(void)add{ num++; UIImage *backimg=[UIImage imageNamed:@"2.png"];
UIImageView *backview=[[UIImageView alloc] initWithImage:backimg];
backview.frame=CGRectMake(0, (num-1)*ImageHeight, 320, ImageHeight);
backview.tag = num+100; [scrollView addSubview:backview]; if (num>3) {
scrollView.contentSize=CGSizeMake(320,num*ImageHeight);
}
} //删除一个书架
-(void)dele{ if (num<=0) {
return;
} for (UIView *view in scrollView.subviews) {
if(view.tag == (num+100))
[view removeFromSuperview];
} num--; if (num>3) {
scrollView.contentSize=CGSizeMake(320,num*ImageHeight);
} } //主界面初始化
-(void)reloadView{ NSLog(@"reloadView");
//遍历当前界面的所有子界面,把子界面删除干净
for(UIView *view in scrollView.subviews){
[view removeFromSuperview];
} scrollView.showsVerticalScrollIndicator=NO;
scrollView.showsHorizontalScrollIndicator=NO;
scrollView.delegate=self;
[scrollView setScrollEnabled:YES]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

【代码笔记】iOS-点击加号增加书架,点击减号减少书架的更多相关文章

  1. easyUI在使用字符串拼接时样式不起作用,点击加号增加一行,点击减号删除一行效果。

    拼接的按钮没有样式,需要使用 var str = $("<a href='javascript:void(0)' class='easyui-linkbutton' onclick=' ...

  2. iOS中CollectionView由于多次点击造成错误的解决方案

    iOS中CollectionCiew由于多次点击,会给程序造成错误. 这个时候,我们可以用过手势类来进行判断和过滤. 但是,有一个快捷的解决方法,那就是给用户响应增加延时操作. 具体代码如下: [co ...

  3. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  4. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  5. 如何让dedecms文章点击量增加一定的数值

    用dedecms建站都知道有一个文章点击量这个参数,我们可不可以用这个浏览量做些延伸扩展呢?比如加上一个固定值变成另外一个指标.很多朋友已经想到了,如下图,我们将本文浏览量286设为点击量,加上300 ...

  6. 前端学习:JS(面向对象)代码笔记

    前端学习:JS(面向对象)代码笔记 前端学习:JS面向对象知识学习(图解) 创建类和对象 创建对象方式1调用Object函数 <body> </body> <script ...

  7. ios h5 app avalon tap点击事件失效及点击延迟300ms问题解决方法

    1.ios h5 app avalon tap事件失效 使用MUI制作app界面,使用avalon.js渲染数据,发现在(Android上正常)ios上运行时容器div的avalon的ms-on-ta ...

  8. 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程

    一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...

  9. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

随机推荐

  1. linux如何编译安装新内核支持NTFS文件系统?(以redhat7.2x64为例)

    内核,是一个操作系统的核心.它负责管理系统的进程.内存.设备驱动程序.文件和网络系统,决定着系统的性能和稳定性.Linux作为一个自由软件,在广大爱好者的支持下,内核版本不断更新.新的内核修订了旧内核 ...

  2. 【原创】Kakfa utils源代码分析(二)

    我们继续研究kafka.utils包 八.KafkaScheduler.scala 首先该文件定义了一个trait:Scheduler——它就是运行任务的一个调度器.任务调度的方式支持重复执行的后台任 ...

  3. 在C#中,不安装Oracle客户端如何连接Oracle数据库

    本方法优点: 1.程序内集成Oracle客户端,无需用户自行进行配置 本方法缺点: 2.增加程序包的体积(Oracle instant client本身有几十兆大小) 下面说一下如何实现. 0.首先, ...

  4. 为什么要用 Bootstrap

    [Bootstrap](http://hovertree.com/menu/bootstrap/) 是由两个 twitter 员工开发并开源的前端框架,非常火爆,而如此火爆自然有它的道理,在我们团队的 ...

  5. C#利用浏览按钮获得文件路径和文件夹路径

    生成文件夹路径 private void btnChoose_Click(object sender, EventArgs e) {            using (OpenFileDialog ...

  6. jquery简单原则器(匹配索引为指定值的元素)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. AlertDialog.Builder弹出对话框

    在Android中,弹出对话框使用AlertDialog.Builder方法. new AlertDialog.Builder(MainActivity.this).setTitle("本机 ...

  8. Firemonkey 指定 StringGrid 只能上下滾动,不要左右滚动

    要使 StringGrid 只能上下滚动,不要左右滚动,只要加入下面代码即可: StringGrid1.AniCalculations.TouchTracking := [ttVertical]; p ...

  9. Redis配置集群二(window)

    第一篇那redis的基础命令都差不多讲了一遍了,这篇就将怎么配置集群了,最后要达到的效果是一台主redis,还有几台从的redis,每次数据都是同步的,当主redis挂掉了,那么就会从几台从redis ...

  10. Eclipse功能集合

    大家好,这篇博客的目的是总结一下Eclipse这个软件中一些不为常用的功能.与大家分享.谢谢~ 1.利用one hour看了一下Eclipse的使用,用two hour写了这篇blog. 2.在现实项 ...