Giter Site home page Giter Site logo

handmadecalendarofswift's Introduction

handMadeCalendarOfSwift

ライブラリを使わないカレンダーサンプル(Swift)

HandMadeCalendar(Swift版)

■概要
ライブラリを使わずにボタンとラベルで実装したシンプルなカレンダーです。

■動作

  1. 表示されているカレンダーをクリックすると、Xcodeのデバッグエリアに選択したカレンダーの年月日が表示されます。
  2. func buttonTapped(button: UIButton)...の中に処理を記載することで、画面遷移等の処理の追記が容易にできます。
  3. ボタン「Next Month」「Prev Month」を押すとでページング処理が行われます。
  4. 上のラベルでは、どの年月のカレンダーを見ているかが表示されます。

■処理の説明

  1. はじめに、現在(初期表示時)の日付を取得する。
  2. その後、カレンダーの始まる位置を決定するためにカレンダーの選択月の1日(yyyy年mm月1日)のデータを取得する。
    データが取得出来たら、それを元にカレンダーの表示位置を計算して日付が入ったボタンを画面上に追加する。
  3. ページング処理を行った際は、年と月のメンバ変数を変えた上で②の処理を行う。

■検証シミュレータ
以下のシミュレータでの動作およびレイアウトの検証を行っています。
*iPhone4s
*iPhone5
*iPhone5s
*iPhone6
*iPhone6 plus

2015/01/08: 暫定的なマルチデバイス対応を上記のエミュレータにて検証しています。

対応させる場合は下記を参考にして頂ければと思います。

  1. 曜日表示ラベルの調整
    (ViewController.swift)
    calendarBaseLabel.frameのCGReckMake内の数値を変更しての調整が可能です。

  2. カレンダーボタンの調整
    (ViewController.swift)
    下記の変数部分の数値を変更しての調整が可能です。

var positionX   = 15 + 50 * (i % 7);
var positionY   = 80 + 50 * (i / 7);
var buttonSizeX = 45;
var buttonSizeY = 45;

※ボタンサイズを変更の際は下記の部分の数値の変更も行って下さい。

button.layer.cornerRadius = 22.5

(きれいな正円にする場合は、[ボタンサイズ÷2]を設定して下さい )

■ちなみにこんな使い方ができます

  1. 日本の祝日への対応
  2. 画面遷移をして次の行き先へ日付の値を引き継ぐ
  3. 色や背景などデザインのカスタマイズ
    ※参考
    その他色々ご活用下さい!

■ライセンス等
特に使用制限はありませんので、どなた様でもご自由にお使い頂くことができます。

■作者より
まだまだ甘い部分があるかもしれませんが、その際はPull Request等を送っていただければ幸いです。アプリ開発の中でこのサンプルが少しでもお役にたつ事ができれば嬉しい限りです。

handmadecalendarofswift's People

Contributors

fumiyasac avatar karamage avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.