Change of buttons’ color of UISegmentedControl


I want you to choose exclusively “Month” and “All”, or “Timeline” and “Tag” in the following example. However, we cannot divide UISegmentedControl into two or more groups. I would like to express it by coloring each button.

NewImage

In the state of the first stage, “Month” and “Timeline” are chosen, respectively.

NewImage

If “All” is touched, the color of “Month” will disappear and a color will be attached to “All.” It is changeless to “Timeline” and “Tag.”

NewImage

Furthermore, a touch of “Tag” will change the color of a button similarly.

Sample code is below.

 

- (void)viewWillAppear:(BOOL)animated {
	
    navigationSegment = [[UISegmentedControl alloc] initWithItems:nil];
    navigationSegment.segmentedControlStyle = UISegmentedControlStyleBar;
    navigationSegment.momentary = YES;
    
    //initialize UISegmentedControl
    //UISegmentedControlの初期化
    [navigationSegment insertSegmentWithTitle:NSLocalizedString(@"month", @"Month")  atIndex:0 animated:NO];
    [navigationSegment insertSegmentWithTitle:NSLocalizedString(@"all", @"All")  atIndex:1 animated:NO];
    [navigationSegment insertSegmentWithTitle:NSLocalizedString(@"sorttime",@"Timeline")  atIndex:2 animated:NO];
    [navigationSegment insertSegmentWithTitle:NSLocalizedString(@"sorttag",@"Tag")  atIndex:3 animated:NO];
    [navigationSegment insertSegmentWithImage:[UIImage imageNamed: @"mail2.png"] atIndex:4 animated:NO];
    
    //call controlPressed when UISegmentedControl is pushed
    //UISegmentedControlが押されたら、controlPressedメソッドを呼ぶ
    [navigationSegment addTarget:self action:@selector(controlPressed:) forControlEvents:UIControlEventValueChanged];

    //Initial value: Month and Timeline is ON.
    //初期値はMonthがON,TimelineがON
    tagOrTime = TIMELINE_FLAG_ON;
    allOrMonth = MONTH_FLAG_ON;
    
    //When view is displayed, objectAtIndex(es) are 0, 1, 2, 3, and 4 from the left.
    //viewが表示されたときは、objectAtIndexは左から0,1,2,3,4。
    [[[navigationSegment subviews] objectAtIndex:0] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
    [[[navigationSegment subviews] objectAtIndex:1] setTintColor:nil];
    [[[navigationSegment subviews] objectAtIndex:2] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
    [[[navigationSegment subviews] objectAtIndex:3] setTintColor:nil];

    
    
}


- (void)controlPressed:(id)sender{
    int index = navigationSegment.selectedSegmentIndex;
    
    if(index == 2){
        tagOrTime = TIMELINE_FLAG_ON;
    }else if(index == 3){
        tagOrTime = TAG_FLAG_ON;
    }else if(index == 0){
        allOrMonth = MONTH_FLAG_ON;
    }else if(index == 1){
        allOrMonth = ALL_FLAG_ON;
    }else if(index == 4){
    	....
    }
    
    //Since the turn of Subview of UISegmentedControl changes irregularly, it rearranges from the left.
    //UISegmentedControlのSubviewの順番がなぜかコロコロ変わってしまうので、左から並び替える。
    NSArray *sortedViews = [navigationSegment.subviews sortedArrayUsingFunction:compareViewsByOrigin context:NULL];

    //A flag is changed according to the button pushed now.
    //現在押されているボタンに従って、フラグを変更する。
    if (tagOrTime == TAG_FLAG_ON) {
        [[sortedViews  objectAtIndex:2] setTintColor:nil];
        [[sortedViews  objectAtIndex:3] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
    } else {
        [[sortedViews objectAtIndex:3] setTintColor:nil];
        [[sortedViews objectAtIndex:2] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
        
    }
    
    if (allOrMonth == ALL_FLAG_ON) {
        [[sortedViews objectAtIndex:0] setTintColor:nil];
        [[sortedViews objectAtIndex:1] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
    } else {
        [[sortedViews objectAtIndex:1] setTintColor:nil];
        [[sortedViews objectAtIndex:0] setTintColor:[UIColor colorWithRed: 0/255.0 green:32/255.0 blue:128/255.0 alpha:0.2]];
    }

    // Remove all original segments from the control
    // 一旦Subviewをすべて削除
    for (id view in navigationSegment.subviews) {
        [view removeFromSuperview];
    }
    
    // Append sorted and colored segments to the control
    // 色を変えたsubviewを付け替える
    for (id view in sortedViews) {
        [navigationSegment addSubview:view];
    }

}
         
//subviews sort function
//ソート関数
NSInteger static compareViewsByOrigin(id sp1, id sp2, void *context)
{
    // UISegmentedControl segments use UISegment objects (private API). But we can safely cast them to UIView objects.
    float v1 = ((UIView *)sp1).frame.origin.x;
    float v2 = ((UIView *)sp2).frame.origin.x;
    if (v1 < v2)
        return NSOrderedAscending;
    else if (v1 > v2)
        return NSOrderedDescending;
    else
        return NSOrderedSame;
}

Thank you, https://goddess-gate.com/dc2/index.php/post/454

【iOS】おさいふをアップデートしました


iPhoneアプリ「おさいふ」をアップデートしました。ぜひお試しください!

「おさいふ」は、単純なインターフェースで「続けられる家計簿入力」をコンセプトに作成しました。おさいふの入力をネットワーク経由でお友達やご夫婦で共有できること、最低2タップで入力が完了することが大きな特徴です。

(1.2.0でのアップデート)

・入力画面の使い勝手をよくしました。「タグ(摘要)」から、金額のフィールドをタップして、連続で入力できるようにしました。今までは一回一回「完了」ボタンを押さないといけなかったもので。

・おさいふ選択画面で、残高表示されるようにしました。

・リスト画面で、現在どの表示方法を選択しているか、わかりやすい配色にしました。

(1.1.0でのアップデート)

・プリセットボタンに別名を付けられることで、例えばボタンには食事の絵文字、タグ(摘要)には「ランチ」と別々に設定できるようにしました。

 

How to get people to rate your IOS app


How to display UIAlert like “Rate this application” when application starts.

NewImage

You should write about UIAlert to didFinishLaunchingWithOptions.

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    CGRect frameForWindow = [[UIScreen mainScreen] bounds];
    window = [[UIWindow alloc] initWithFrame:frameForWindow];

    //write about window
    //ウインドウについて記載

    [window addSubview:navigationController.view];

    //From here about UIAlert and rating popup.
    //manage displaying UIAlert by NSUserDefaults
    //ここからUIAlertについて記載。表示するかどうかはNSUserDefaultsで制御する。
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSInteger executeTime = [userDefaults integerForKey: @"executeTime"];
    NSInteger alertDispFlag = [userDefaults integerForKey: @"alertDispFlag"];

    executeTime++;

    //If this application is started 6 times or more and alertDispFlag == 0, then alert is displayed.
    //もし6回以上起動していて、alertDispFlagが0なら表示する
    if (executeTime > 5 && alertDispFlag == 0) {
        // アラート表示

        UIAlertView *alertView = [[UIAlertView alloc] init];
        alertView.delegate = self;
        alertView.title=NSLocalizedString(@"pleaseReview", @"Please Rate");
        alertView.message=NSLocalizedString(@"appliciate", @"Please Rate this apps.");
        [alertView addButtonWithTitle:NSLocalizedString(@"Review", @"Rate now.")];
        [alertView addButtonWithTitle:NSLocalizedString(@"Later", @"Remind me later.")];
        [alertView addButtonWithTitle:NSLocalizedString(@"nothanks", @"No, thanks.")];
        [alertView show];
        [alertView release];

    }

    [userDefaults setInteger:executeTime forKey: @"executeTime"];
    [userDefaults synchronize];

    return YES;
}

//UIAlartのデリゲート。UIAlertの動作を記載する。
//delegate to UIAlret

-(void)alertView:(UIAlertView*)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    switch (buttonIndex) {
        case 0:
            //go to rate page
            [userDefaults setInteger: 1 forKey: @"alertDispFlag"];
            [userDefaults synchronize];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:NSLocalizedString(@"reviewURL", @"") ]];
            break;

        case 1:

            break;
        case 2:
            [userDefaults setInteger: 1 forKey: @"alertDispFlag"];
            [userDefaults synchronize];
            break;
    }

}

review URL is

itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=(9 digit itunes app id)&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software

Arduino uno + ethernet shield + iPhone + iOSC(OSC Application)


Arduino uno + ethernet shield + iPhone + iOSC(OSC Application)

A LCD didn’t work when I was coding like below.

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

Take care about a LCD connection port.

I referred to UDPSendReceiveString, Arduino examples (Ethernet).

/*
  UDPSendReceive.pde:
 */

#include          // needed for Arduino versions later than 0018
#include 
#include          // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[]	= { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
byte ip[]	= { 192 , 168 , 1 , 1 } ;  //

unsigned int localPort = 10000;      // local port to listen on

// the next two variables are set when a packet is received
byte remoteIp[4];        // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back
LiquidCrystal lcd(8, 7, 6, 5, 4, 3, 2);

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0, 0);

  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.available(); // note that this includes the UDP header
  if(packetSize)
  {
    packetSize = packetSize - 8;      // subtract the 8 byte header
    Serial.print("Received packet of size ");
    Serial.println(packetSize);

    // read the packet into packetBufffer and get the senders IP addr and port number
    Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
    char* c = packetBuffer;
    if( strcmp(c, "/osc/button1") == 0 ){
      lcd.setCursor(0,0);
      lcd.print("button 1 pushed");
    }
    if ( strcmp(c, "/osc/button2") == 0 ){
      lcd.setCursor(0,0);
      lcd.print("button 2 pushed");
    }
    Udp.sendPacket( ReplyBuffer, remoteIp, remotePort);
  }
  delay(500);
}

(日本語) iPhone Programming : OpenCV + AVFoundation – First step of AR


隠レター 公開開始


samurai-appsは本日,「隠レター」をリリースしました. ご自分の写真に秘密の画像を埋め込めると言うものです.6月25日までは無料で配布しておりますので,ダウンロードして頂き,ぜひご感想をお寄せください. 詳しくはこちらから!

Calolog FREE 公開開始


ご好評いただいているCalolog(カロログ)の無料配布版を本日,公開しました.

機能的な制限はありませんが,広告が出ます.

今後ともsamurai-appsをよろしくお願い申し上げます.

Calolog FREE (iTunes)

アイデアの小槌+ Build 20091007.00 公開

5秒の強制思考時間のON/OFFを選択できるようになりました.

アイデアの小槌/アイデアの小槌+ Build 20090811.00 公開

続きを読む

© 2018 samurai-apps. All rights reserved. Powered by WordPress Entries RSS Comments RSS