【Mac】gif2apng


不想裝 Imagemagick 可以直接試試輕巧的 gif2apng
雖然官網有提示如何批次轉換,但卻無法成功。以下提供另一個方式。

for img in *.gif; do
    filename=${img%.*}
    gif2apng "$filename.gif" "$filename.png"
done

參考

【Mac】SiteSucker


SiteSucker 是 mac 版的 Teleport。可由 App Store 下載。

image

【Mac】cscope


參考 https://anylinux.net/post/2453.html

【iOS】Shortcuts for XCode 4


  • Command + Enter
    Command + Option + Enter

【iOS】Animations


 

  • AnimationCurve
    - UIViewAnimationCurveEaseIn
    - UIViewAnimationCurveEaseInOut
    - UIViewAnimationCurveEaseOut
    - UIViewAnimationCurveLinear
  • AnimationTransition
    - UIViewAnimationTransitionCurlUp
    - UIViewAnimationTransitionFlipFromRight
    - UIViewAnimationTransitionFlipFromLeft
  • 基本框架

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                           forView:self.view cache:YES];

    // Action

    [UIView commitAnimations];

  • 框架範例二

    CATransition *animation = [CATransition animation];
    [animation setDuration:0.5];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [self.view.layer addAnimation:animation forKey:nil];

    //do something here

    [CATransaction commit];

【iOS】Keyboard


 

  • 讓 TextField 所帶出的 Keyboard 消失

    - (IBAction) textFieldReturn:(id)textField
    {
        [textField resignFirstResponder];
    }

【iOS】Plist 存取


 

  • 參考 Property List Tutorial – using plist to store user data, 以下截取重要部分.
  • 建立 Data.plist 放在 Resources 底下
    image
  • 宣告

    @interface PlistTutorialViewController : UIViewController
    {
        IBOutlet UITextField    *nameEntered;
        IBOutlet UITextField    *homePhone;
        IBOutlet UITextField    *workPhone;
        IBOutlet UITextField    *cellPhone;
       
        NSString        *personName;
        NSMutableArray    *phoneNumbers;
    }

    @property (nonatomic, retain)    UITextField        *nameEntered;
    @property (nonatomic, retain)    UITextField        *homePhone;
    @property (nonatomic, retain)    UITextField        *workPhone;
    @property (nonatomic, retain)    UITextField        *cellPhone;

    @property (nonatomic, retain)    NSString        *personName;
    @property (nonatomic, retain)    NSMutableArray    *phoneNumbers;

    - (IBAction) saveData;
    - (IBAction) textFieldReturn:(id)textField;

  • 讀取

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Data.plist code
        // get paths from root direcory
        NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
        // get documents path
        NSString *documentsPath = [paths objectAtIndex:0];
        // get the path to our Data/plist file
        NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
       
        // check to see if Data.plist exists in documents
        if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
        {
            // if not in documents, get property list from main bundle
            plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
        }
       
        // read property list into memory as an NSData object
        NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
        NSString *errorDesc = nil;
        NSPropertyListFormat format;
        // convert static property liost into dictionary object
        NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                                              propertyListFromData:plistXML
                                              mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                              format:&format
                                              errorDescription:&errorDesc];
        if (!temp)
        {
            NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
        }
        // assign values
        self.personName = [temp objectForKey:@"Name"];
        self.phoneNumbers = [NSMutableArray arrayWithArray:[temp objectForKey:@"Phones"]];
        // display values
        nameEntered.text = personName;
        homePhone.text = [phoneNumbers objectAtIndex:0];
        workPhone.text = [phoneNumbers objectAtIndex:1];
        cellPhone.text = [phoneNumbers objectAtIndex:2];
    }

  • 寫入

    - (IBAction) saveData
    {
        // get paths from root direcory
        NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
        // get documents path
        NSString *documentsPath = [paths objectAtIndex:0];
        // get the path to our Data/plist file
        NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
       
        // set the variables to the values in the text fields
        self.personName = nameEntered.text;
        self.phoneNumbers = [[NSMutableArray alloc] initWithCapacity:3];
        [phoneNumbers addObject:homePhone.text];
        [phoneNumbers addObject:workPhone.text];
        [phoneNumbers addObject:cellPhone.text];
       
        // create dictionary with values in UITextFields
        NSDictionary *plistDict = [NSDictionary
                                   dictionaryWithObjects:
                                   [NSArray arrayWithObjects: personName, phoneNumbers, nil]
                                   forKeys:[NSArray arrayWithObjects: @"Name", @"Phones", nil]];
       
        NSString *error = nil;
        // create NSData from dictionary
        NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict
                                                                       format:NSPropertyListXMLFormat_v1_0
                                                             errorDescription:&error];
       
        // check is plistData exists
        if(plistData)
        {
            // write plistData to our Data.plist file
            [plistData writeToFile:plistPath atomically:YES];
        }
        else
        {
            NSLog(@"Error in saveData: %@", error);
            [error release];
        }
    }

【iOS】fmdb


fmdb, 更加簡化 Sqlite 的操作.

【iOS】CustomBadge


CustomBadge

  • 範例, 顯示兩個 Badge, 或可以說是一個, 技巧就是把一個疊在另一個上面.
    image

    CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"
                                                       withStringColor:[UIColor whiteColor]
                                                        withInsetColor:[UIColor redColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor whiteColor]
                                                             withScale:1.0
                                                           withShining:YES];
    CustomBadge *customBadge2 = [CustomBadge customBadgeWithString:@"CustomBadge"
                                                       withStringColor:[UIColor blackColor]
                                                        withInsetColor:[UIColor greenColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor yellowColor]
                                                             withScale:1.5
                                                           withShining:YES];
        
    [customBadge1 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge1.frame.size.width/2+customBadge2.frame.size.width/2, 110, customBadge1.frame.size.width, customBadge1.frame.size.height)];
    [customBadge2 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge2.frame.size.width/2, 110, customBadge2.frame.size.width, customBadge2.frame.size.height)];

        [self.view addSubview:customBadge2];
        [self.view addSubview:customBadge1];

【iOS】UISegmentedControl


  • 初始

        UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:
                                       [NSArray arrayWithObjects: @"Mail", @”SMS”, nil]];
        segment.frame =  CGRectMake(10, 10, 200, 35);
        segment.selectedSegmentIndex = NSIntegerMax;
        segment.tag = 3;
        [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        segment.segmentedControlStyle = UISegmentedControlStyleBar;
        [self.view addSubview:segment];

  • 加入 badge,  要搭配 CustomBadge
    image

    - (IBAction) segmentAction:(id)sender
    {
        UISegmentedControl *segment = (UISegmentedControl*) sender;
        NSLog(@"UIControlEventValueChanged:%d", segment.selectedSegmentIndex);
        segment.enabled = NO;
    }
    - (void) viewDidLoad
    {

        UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:
                                       [NSArray arrayWithObjects: @"Mail", @"SMS", nil]];
        segment.frame =  CGRectMake(10, 10, 200, 35);
        segment.selectedSegmentIndex = NSIntegerMax;
        segment.tag = 3;
        [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
        segment.segmentedControlStyle = UISegmentedControlStyleBar;
        [self.view addSubview:segment];
       
        CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"32"
                                                       withStringColor:[UIColor whiteColor]
                                                        withInsetColor:[UIColor greenColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor whiteColor]
                                                             withScale:1.0
                                                           withShining:YES];       
       
        [customBadge1 setFrame:CGRectMake(90, 0, 20, 20)];
        [self.view addSubview:customBadge1];
       
        CustomBadge *customBadge2 = [CustomBadge customBadgeWithString:@"33"
                                                       withStringColor:[UIColor whiteColor]
                                                        withInsetColor:[UIColor redColor]
                                                        withBadgeFrame:YES
                                                   withBadgeFrameColor:[UIColor whiteColor]
                                                             withScale:1.0
                                                           withShining:YES];       
       
        [customBadge2 setFrame:CGRectMake(190, 0, 20, 20)];
        [self.view addSubview:customBadge2];

        [self.view bringSubviewToFront:customBadge1];
        [self.view bringSubviewToFront:customBadge2];
        }

【iOS】UISwitch


  • 初始化

    UISwitch *switch= [ [ UISwitch alloc ] initWithFrame: CGRectMake(200, 10, 0, 0) ];
    switch.on = NO;
    switch.tag = 2;
    [switch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [self addSubview: jumpToNextAuto];

  • 縮小要用 transform
    switch.transform = CGAffineTransformMakeScale(0.75, 0.75);

【iOS】UIImage


 

 

Ed32. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com