Giter Site home page Giter Site logo

simpleswitchbutton's Introduction

SimpleSwitchButton

On/Off切り替え可能なボタン(Switchのようなボタン)を作成できます。 On, Offそれぞれの状態に対し画像を設定することで、ボタンの状態を表現できます。

複数のボタンをSimpleSwitchButtonCollectionで管理することによって、

  • Switchボタンのうちどれか一つのみを選択できるラジオボタン
  • いくつでも選択可能なチェックボックス

のようなUIをつくることができます。 ついでにall On/Offメソッドやtoggleメソッドなども用意しました。

動作イメージ:

動作イメージ

インストール

デモ内にある以下の4つをプロジェクトに追加

  • SimpleSwitchButtonCollection.h
  • SimpleSwitchButtonCollection.m
  • SimpleSwitchButton.h
  • SimpleSwitchButton.m

使用したいファイルでSimpleSwitchButtonCollection.hをインポート

以下のように、simpleSwitchButtonCollectionを一つと、SimpleSwitchButtonを必要なだけ生成し、ビューに加える。

SimpleSwitchButtonCollection* simpleSwitchButtonCollection = [[SimpleSwitchButtonCollection alloc] initWithSimpleSwitchButtonMode:asCheckBox];

SimpleSwitchButton *ore = [simpleSwitchButtonCollection createSimpleSwitchButtonForKey:@"ore" ButtonFrame:CGRectMake(0, 50, 100, 100) OnImageName:@"ore_on.png" OffImageName:@"ore_off.png"];
[self.view addSubview:ore];

SimpleSwitchButton *mido = [simpleSwitchButtonCollection createSimpleSwitchButtonForKey:@"mido" ButtonFrame:CGRectMake(100, 50, 100, 100) OnImageName:@"mido_on.png" OffImageName:@"mido_off.png"];
[self.view addSubview:mido];

ONになっているキーの数や、ONになっているキーを取得したい場合は以下のように

int counter = [simpleSwitchButtonCollection countOnItems];
NSArray* onKeys = [simpleSwitchButtonCollection getKeysOfOnItem]);

詳しくはデモを参照。
勢いで作ったのでちゃんとテストしてません。
バグがあったら教えてください・・・。

simpleswitchbutton's People

Contributors

matsu-chara avatar

Watchers

James Cloos 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.