2011年10月12日 星期三

char * <-> NSData


char* to NSData
[NSData dataWithBytes:myImageData length:myImageDataLength]
NSData to char*
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data bytes], len);

2011年10月11日 星期二

計算字串長度

CGFloat w = [title sizeWithFont:[UIFont fontWithName:@"Arial" size:18]].width; 

自定義View之間切換動畫


- (void) pushController: (UIViewController*) controller
         withTransition: (UIViewAnimationTransition) transition
{
    [UIView beginAnimations:nil context:NULL];
    [self pushViewController:controller animated:NO];
    [UIView setAnimationDuration:.
5];
    [UIView setAnimationBeginsFromCurrentState:YES];     
    [UIView setAnimationTransition:transition forView:self.view cache:YES];
    [UIView commitAnimations];
}
    或者:
CATransition *transition = [CATransition animation];
transition.duration 
= kAnimationDuration;
transition.timingFunction 
= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type 
= kCATransitionPush;
transition.subtype 
= kCATransitionFromTop;
transitioning 
= YES;
transition.
delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
 
self.navigationController.navigationBarHidden 
= NO;
[self.navigationController pushViewController:tableViewController animated:YES];

2011年10月5日 星期三

UISearchBar disable auto disable of cancel button


for (UIView *possibleButton in searchBar.subviews)
{
    if ([possibleButton isKindOfClass:[UIButton class]])
    {
        UIButton *cancelButton = (UIButton*)possibleButton;
        cancelButton.enabled = YES;
        break;
    }
}

2011年10月4日 星期二

customize the text of navigationbar


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.font = [UIFont boldSystemFontOfSize:14.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = [dataItem objectForKey:@"title"];
[label release];