Skip to content

Instantly share code, notes, and snippets.

@somtd
Created December 9, 2013 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somtd/7872351 to your computer and use it in GitHub Desktop.
Save somtd/7872351 to your computer and use it in GitHub Desktop.
C4 sample project "Music List" #BLOG
#import "SongListWorkSpace.h"
@interface SongListWorkSpace ()
@end
@implementation SongListWorkSpace {
C4Button *songButton;
C4Image *songImage;
C4Label *songTitleLabel;
C4Label *composerLabel;
C4Shape *circle;
}
-(void)setup
{
_currentSongTag = 0;
[self setupSongLabel];
}
-(void)setupSongLabel
{
for (int i = 0; i < songListCount; i++) {
//Button
songButton = [C4Button buttonWithType:CUSTOM];
songButton.UIButton.tag = i;//UIButtonがProperty
songButton.frame = CGRectMake(0, 80 + (80 * i), 300, 80);
[songButton setBackgroundImage:nil forState:NORMAL];
[songButton runMethod:@"onSongButton:" target:self forEvent:TOUCHUPINSIDE];
//Image
songImage = [C4Image imageNamed:[NSString stringWithFormat:@"%d.png",i]];
songImage.frame = CGRectMake(20, 80 + 12 + (80 * i), 56, 56);
circle = [C4Shape ellipse:CGRectMake(0, 0, songImage.width, songImage.height)];
circle.center = CGPointMake(songImage.width/2 ,songImage.height/2);
songImage.mask = circle;
//Composer
NSString *composer = [self composerNameWithTag:i];
composerLabel = [C4Label labelWithText:composer];
composerLabel.frame = CGRectMake(96, 80 + 15 + (80 * i), 220, 30);
composerLabel.textColor = [UIColor lightGrayColor];
composerLabel.font = [C4Font fontWithName:@"ArialRoundedMTBold" size:30.0f];
//Title
NSString *songTitle = [self songTitleWithTag:i];
songTitleLabel = [C4Label labelWithText:songTitle];
songTitleLabel.frame = CGRectMake(96, 80 + 15 + 30 + (80 * i), 220, 14);
songTitleLabel.textColor = [UIColor lightGrayColor];
songTitleLabel.font = [C4Font fontWithName:@"ArialRoundedMTBold" size:12.0f];
[self.canvas addLabel:songTitleLabel];
[self.canvas addLabel:composerLabel];
[self.canvas addSubview:songImage];
[self.canvas addSubview:songButton];
}
}
-(void)onSongButton:(id)sender
{
UIButton *selectSongButton = (UIButton *)sender;
_currentSongTag = selectSongButton.tag;
[self.delegate selectedSong:_currentSongTag];
}
-(NSString *)songTitleWithTag:(songListTag)tag
{
switch (tag) {
case Beethoven:
return @"交響曲第9番 第4楽章";
break;
case Ravel:
return @"ボレロ";
break;
case Bizet:
return @"カルメン 第1幕への前奏曲";
break;
case Dvorak:
return @"交響曲第9番 新世界より 第4楽章";
break;
case Rachmaninov:
return @"ピアノ協奏曲第2番 第3楽章";
break;
default:
return nil;
break;
}
}
-(NSString *)composerNameWithTag:(songListTag)tag
{
switch (tag) {
case Beethoven:
return @"Beethoven";
break;
case Ravel:
return @"Ravel";
break;
case Bizet:
return @"Bizet";
break;
case Dvorak:
return @"Dvořák";
break;
case Rachmaninov:
return @"Rachmaninov";
break;
default:
return nil;
break;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment