無限滑動,顯示一個星期的單行日曆
思路 獲取當前時間 向前向後計算出一個星期的時間放進陣列,,右劃時根據週日時間向後計算七天。。。左滑根據週一時間向前計算七天,,,底部是scrollview,新增三個View 每個View上七個Label , 迴圈思路是右劃完成 第二個View回到中間 資料發生改變,,左劃完成 第二個View仍回到中間 資料發生改變 給人的錯覺是一直可以迴圈滑動
核心程式碼
- (void)createView{
self.titleLabel = [[UILabelalloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 30)];
self.titleLabel
[selfaddSubview:self.titleLabel];
_nsdateArray = [NSMutableArrayarray];
self.dateArray = [NSMutableArrayarray];
//
self.titleLabel.text = [selfgetNowDate:[NSDatedate]];
NSArray *weekArr = @[@"週一",@"週二",@"週三",@"週四",@"週五",@"週六",@"週日"];
for (NSInteger i = 0; i<7
UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(i*self.frame.size.width/7, 30, self.frame.size.width/7, 30)];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFontsystemFontOfSize:12];
label.text = weekArr[i];
[self addSubview:label];
}
self.backScrollView
self.backScrollView.contentSize = CGSizeMake(self.frame.size.width*3, 0);
[selfaddSubview:self.backScrollView];
self.backScrollView.delegate = self;
self.backScrollView.pagingEnabled = YES;
self.backScrollView.showsHorizontalScrollIndicator = NO;
self.dateViewArr = [NSMutableArrayarray];
///
NSInteger a = [selfgetDayChafromMonday:[selfgetNowWeek]];
NSInteger b = [selfgetDayChaToSunday:[selfgetNowWeek]];
/// 當前星期格式化時間
self.dateArray = [selfgetDateArrCarFro:a chaTo:b];
/// 當前星期標準時間
self.nsdateArray = [selfgetNsDateArrCarFro:a chaTo:b];
///// 一開始的顯示不要呼叫leftButtonAction,rightButtonAction方法,防止左右滑時資料出錯
for (NSInteger i = 0; i<3; i++) {
self.dateView = [[dateViewalloc] initWithFrame:CGRectMake(self.frame.size.width*i, 0, self.frame.size.width, 40)];
[self.backScrollViewaddSubview:self.dateView];
[self.dateViewArraddObject:self.dateView];
if (i==0) {
NSMutableArray *dateArray = [NSMutableArrayarray];
NSMutableArray *nsdateArray = [NSMutableArrayarray];
NSDate *date = [self.nsdateArray firstObject];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDate dateWithTimeInterval:-24*60*60*i sinceDate:date];//前i天
[dateArray insertObject:[self getDateArr:lastDay] atIndex:0];
[nsdateArray insertObject:lastDay atIndex:0];
}
[self.dateView reloadButtonTitle:dateArray nsDateArr:nsdateArray];
}else if (i==1) {
NSInteger a = [selfgetDayChafromMonday:[selfgetNowWeek]];
NSInteger b = [selfgetDayChaToSunday:[selfgetNowWeek]];
self.dateArray = [selfgetDateArrCarFro:a chaTo:b];
[self.dateViewreloadButtonTitle:self.dateArraynsDateArr:self.nsdateArray];
}else{
NSMutableArray *dateArray = [NSMutableArrayarray];
NSMutableArray *nsdateArray = [NSMutableArrayarray];
NSDate *date = [self.nsdateArray lastObject];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDate dateWithTimeInterval:+24*60*60*i sinceDate:date];//後i天
[dateArray addObject:[self getDateArr:lastDay]];
[nsdateArray addObject:lastDay];
}
[self.dateView reloadButtonTitle:dateArray nsDateArr:nsdateArray];
}
}
[selfsetScrollViewContentOffsetCenter];
}
/// 偏移到中心位置
- (void)setScrollViewContentOffsetCenter {
[self.backScrollViewsetContentOffset:CGPointMake(self.frame.size.width, 0) animated:NO];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
int contentOffsetX = scrollView.contentOffset.x;
/// 右劃
if(contentOffsetX >= (2 * self.frame.size.width)) {
/// 重新整理中間頁日期
[selfrightScrollAction];
[self.dateViewArr[1] reloadButtonTitle:self.dateArraynsDateArr:self.nsdateArray];
/// 重新整理後一頁日期
NSMutableArray *dateArray = [NSMutableArrayarray];
NSMutableArray *nsdateArray = [NSMutableArrayarray];
NSDate *date = [self.nsdateArray lastObject];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDatedateWithTimeInterval:+24*60*60*i sinceDate:date];//後i天
[dateArray addObject:[self getDateArr:lastDay]];
[nsdateArray addObject:lastDay];
}
[self.dateViewArr[2] reloadButtonTitle:dateArray nsDateArr:nsdateArray];
/// 重新整理前一頁日期
NSMutableArray *ldateArray = [NSMutableArrayarray];
NSMutableArray *lnsdateArray = [NSMutableArrayarray];
NSDate *ldate = [self.nsdateArray firstObject];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDatedateWithTimeInterval:-24*60*60*i sinceDate:ldate];//前i天
[ldateArray insertObject:[self getDateArr:lastDay] atIndex:0];
[lnsdateArray insertObject:lastDay atIndex:0];
}
[self.dateViewArr[0] reloadButtonTitle:ldateArray nsDateArr:lnsdateArray];
[self.backScrollViewsetContentOffset:CGPointMake(self.frame.size.width, 0)];
}
/// 左滑
if(contentOffsetX <= 0) {
/// 重新整理中間頁日期
[selfleftScrollAction];
[self.dateViewArr[1] reloadButtonTitle:self.dateArraynsDateArr:self.nsdateArray];
/// 重新整理前一頁日期
NSMutableArray *ldateArray = [NSMutableArrayarray];
NSMutableArray *lnsdateArray = [NSMutableArrayarray];
NSDate *ldate = [self.nsdateArray firstObject];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDatedateWithTimeInterval:-24*60*60*i sinceDate:ldate];//前i天
[ldateArray insertObject:[self getDateArr:lastDay] atIndex:0];
[lnsdateArray insertObject:lastDay atIndex:0];
}
[self.dateViewArr[0] reloadButtonTitle:ldateArray nsDateArr:lnsdateArray];
/// 重新整理後一頁日期
NSMutableArray *dateArray = [NSMutableArrayarray];
NSMutableArray *nsdateArray = [NSMutableArrayarray];
NSDate *date = [self.nsdateArray lastObject];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDatedateWithTimeInterval:+24*60*60*i sinceDate:date];//後i天
[dateArray addObject:[self getDateArr:lastDay]];
[nsdateArray addObject:lastDay];
}
[self.dateViewArr[2] reloadButtonTitle:dateArray nsDateArr:nsdateArray];
[self.backScrollViewsetContentOffset:CGPointMake(self.frame.size.width, 0)];
}
}
- (void)rightScrollAction{
NSDate *date = [self.nsdateArray lastObject];
[self.dateArrayremoveAllObjects];
[self.nsdateArrayremoveAllObjects];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDatedateWithTimeInterval:+24*60*60*i sinceDate:date];//前i天
[self.dateArray addObject:[self getDateArr:lastDay]];
[self.nsdateArray addObject:lastDay];
}
}
- (void)leftScrollAction{
NSDate *date = [self.nsdateArray firstObject];
[self.dateArrayremoveAllObjects];
[self.nsdateArrayremoveAllObjects];
for (NSInteger i = 1; i<=7; i++) {
NSDate *lastDay = [NSDatedateWithTimeInterval:-24*60*60*i sinceDate:date];//前i天
[self.dateArray insertObject:[self getDateArr:lastDay] atIndex:0];
[self.nsdateArray insertObject:lastDay atIndex:0];
}
}
//// 獲取當前這個星期格式化的時間
- (NSMutableArray *)getDateArrCarFro:(NSInteger)chafro chaTo:(NSInteger)chato{
NSMutableArray *dateArr = [NSMutableArrayarray];
for (NSInteger i = 1; i<=chafro; i++) {
NSDate * date = [NSDate date];//當前時間
NSDate *lastDay = [NSDatedateWithTimeInterval:-24*60*60*i sinceDate:date];//前i天
[dateArr insertObject:[self getDateArr:lastDay] atIndex:0];
}
[dateArr addObject:[self getDateArr:[NSDate date]]];
for (NSInteger i = 1; i<=chato; i++) {
NSDate * date = [NSDate date];//當前時間
NSDate *lastDay = [NSDatedateWithTimeInterval:+24*60*60*i sinceDate:date];//後i天
[dateArr addObject:[self getDateArr:lastDay]];
}
return dateArr;
}
//// 獲取當前這個個星期標準時間
- (NSMutableArray *)getNsDateArrCarFro:(NSInteger)chafro chaTo:(NSInteger)chato{
NSMutableArray *dateArr = [NSMutableArrayarray];
for (NSInteger i = 1; i<=chafro; i++) {
NSDate * date = [NSDate date];//當前時間
NSDate *lastDay = [NSDatedateWithTimeInterval:-24*60*60*i sinceDate:date];//前i天
[dateArr insertObject:lastDay atIndex:0];
}
[dateArr addObject:[NSDatedate]];
for (NSInteger i = 1; i<=chato; i++) {
NSDate * date = [NSDate date];//當前時間
NSDate *lastDay = [NSDatedateWithTimeInterval:+24*60*60*i sinceDate:date];//後i天
[dateArr addObject:lastDay];
}
return dateArr;
}
//// 獲取當前日期 顯示為標題時間
- (NSString *)getNowDate:(NSDate *)senddate{
//獲取系統當前的時間
NSCalendar *cal=[NSCalendarcurrentCalendar];
NSUInteger unitFlags= NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitWeekday|NSCalendarUnitWeekOfMonth|NSCalendarUnitWeekOfYear|NSCalendarUnitWeekday;
NSDateComponents *conponent= [cal components:unitFlags fromDate:senddate];
//獲取年、月、日
NSInteger year = [conponent year];
NSInteger month = [conponent month];
相關推薦
無限滑動,顯示一個星期的單行日曆
思路 獲取當前時間 向前向後計算出一個星期的時間放進陣列,,右劃時根據週日時間向後計算七天。。。左滑根據週一時間向前計算七天,,,底部是scrollview,新增三個View 每個View上七個Label , 迴圈思路是右劃完成 第二個View回到中間 資料發生改變,,左劃完
NGUI 無限滑動,支援定位顯示指定資料
為什麼需要無限滑動: 1:揹包,玩家如果獲取了1000個道具,如果沒有無限滑動的話就只能做成按頁來顯示或者生成1000個格子來顯示 2:排行榜,和揹包同理 無限滑動應用場景在與需要顯示非常多的item的時候 百度了很多ngui的無限滑動都不支援定位顯
ViewPager 無限滑動,往回滑動異常
在實現ViewPager的無限滑動時,遇到了個小坑。往前滑動的時候沒有問題,而當我往回滑動的時候程式崩潰掉。 下面的是出現問題的程式碼: MainActivity.java public class MainActivity extends Activ
編寫一個程式,輸出一個月的日曆。
public class DisplayYueLi{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); String input1=sc.nextLine(); String[] inpu
問題:combo只顯示一個選項,其他不顯示(調整框的高度即可。)
== .com idc 普通 內容 重新 運行 padding href 解決辦法:調整框的高度即可。 轉自:http://blog.163.com/strive_only/blog/static/89380168200971010114665/ 雖然我也是用了好一段VC的
如何高亮顯示一個元素,方便調試
selenium 高亮顯示元素 現在以百度的搜索框為例子,通過兩種方法來高亮顯示百度搜索框第一種方法:from selenium import webdriverdriver = webdriver.Firefox()driver.get(‘https://www.baidu.com/index.php?t
一個星期實現二次開發,解決很多用戶無法解決的問題
解決方案 版本號 臨時性 開發 用戶 最近,收到一個用戶的體驗分享,他用一個星期完成對H3的從陌生到基本熟悉,再從基本屬性到基本二次自定義開發,對於他對我我們H3的支持,我們表示感謝~~以下是對該用戶的實例分享整理。-------------------------------------
Java鏈接HBASE數據庫,創建一個表,刪除一張表,修改表,輸出插入,修改,數據刪除,數據獲取,顯示表信息,過濾查詢,分頁查詢,地理hash
can charat nfa true 目錄結構 dfa byte sin extra 準備工作 1、創建Java的Maven項目 創建好的目錄結構如下: 另外註意junit的版本,最好不要太高,最開始筆者使用的junit4.12的,發現運行的時候會報錯。最後把Junit
JQ 移動端返回頂部,往下滑動時顯示返回按鈕,往上滑動時隱藏返回按鈕
hid 獲取 scroll var 返回 向上 區域 手勢 默認 returnTop:function(){ //預定義返回頂部的html代碼,它的css樣式默認為不顯示 var gotoTop_html = ‘<div class
C# ArcgisEngine開發中,對一個圖層進行過濾,只顯示符合條件的要素
layer style where sky 要求 我們 ase get filter 轉自原文 C# ArcgisEngine開發中,對一個圖層進行過濾,只顯示符合條件的要素 有時候,我們要對圖層上的地物進行有選擇性的顯示,以此來滿足實際的功能要求。 按下面介紹的
設計一個程序,有一個虛擬存儲區和內存工作區,實現下述三種算法中的任意兩種,計算訪問命中率(命中率=1-頁面失效次數/頁地址流長度)。附加要求:能夠顯示頁面置換過程。算法包括:先進先出的算法(FIFO)、最少使用算法(LFU)、最近未使用算法(NUR)
== oat 程序 表示 隊列 ini ++ 等待 進程 第一部分。。。 #include <cstdlib>#include<conio.h> #include<stdio.h>#include<stdlib.h>#incl
同張表中同時查詢兩個字段顯示一個字段,對兩個字段進行按時間排序
principal mount sel con AC code rom inter nbsp select b.bid_name as bidName,bd.repayment_way as depict,r.exact_repayment_time as time, r
vue中循環一個數組,不顯示的問題,弄一個假數據,它反而會循環出來?why?
UC ans res ram 最好的 his get 一個 () 核心:就時this指向的問題,這種情況下最好打印出this看一下 可以在頁面渲染出那個數組 <div>{{listData}}</div>就會看見神奇的事情,竟然時空的解決方案: ge
python webdriver 登陸163郵箱給QQ郵箱發送一個郵件,顯示等待
try body component cte elf them rac send pri #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.web
標簽菜單欄,點擊一個菜單,顯示菜單小標題,另外2個菜單不現實小標題內容
meta ecc width ID 功能 font spl mar 顯示 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <
斐波那契數列,1.1.2.3.5.8......,輸入一個數字,比如3,顯示前面三個數字1,1,2.
int 都是 AR public 運行 sca ... 3.5 info 斐波那契數列(從第三個數字開始都是前面兩個數字的和),1.1.2.3.5.8......,輸入一個數字,比如3,顯示前面三個數字1,1,2. 1 public class practice {
c#版的WinExecAndWait32,執行一個程序,等待他運行完畢,並回顯他的顯示
realtime services sage 參數 work lec tostring 簡單 這一 需要定義部分和執行部分,定義部分基本上是從delphi改過來的,把他另存命名為dWindows.cs,代碼如下: using System; using System.Co
QT中|Qt::Tool類型窗口自動退出消息循環問題解決(setQuitOnLastWindowClosed必須設置為false,最後一個窗口不顯示的時候,程序會退出消息循環)
lan last art true nbsp http https blog 消息 為application 設置setQuitOnLastWindowClosed屬性,確實為true; 將其顯示為false; 退出該應該程序不能調用QDialog的close消息槽,只
執行APP顯示兩個APP圖示,一個打不開,刪除一個後,另一個也會消失。
可能原因:你添加了兩個intent-filter 的LAUNCHER 事件,這種情況尤其在一個專案多個module的時候容易出現 <intent-filter> &nbs
Android RecyclerView一個一個自動滾動,無限迴圈,聊天列表效果,跑馬燈效果
實現效果 看到這個效果,看到很多人用ViewFlipper實現,但是效果並不理想,於是我想到用RecyclerView試試。 主要是監聽recyclerView滑動,開始和暫停來控制,廢話不多說,上程式碼。 自定義RecyclerView public class Auto