iPhone

iphone

zombie45 2011. 5. 23. 14:15
// 세로
if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||
toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){

NSLog(@"vertical");
rect = CGRectMake(0.0, 0.0, 1024.0, 768.0);

topMBar.frame = CGRectMake(0.0, 0.0, 1024.0, 44.0);
// 가로

} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
  toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"horizontal");
rect = CGRectMake(0.0, 0.0, 768.0, 1024.0);
topMBar.frame = CGRectMake(0.0, 0.0, 768.0, 44.0);
}
mVC.frame = rect;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 BOOL returnValue = NO;
 if ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ) {
  returnValue = YES;
 }
 
 return returnValue;
}

CGRect frame = CGRectMake(10, 290, 300, 70);
UIView *background = [[UIView alloc] initWithFrame:frame];
background.backgroundColor = [UIColor blackColor];
background.alpha = 0.8;
background.layer.cornerRadius = 8;
background.layer.masksToBounds = YES;
[self.view addSubview:background];

라운드 사각형 만들기

/UITabBarController+CCAdditions.h
@interface UITabBarController (CCAdditions)

- (void) setBackgroundImage:(UIImage *)i;

@end
//UITabBarController+CCAdditions.m
#import "UITabBarController+CCAdditions.h"

@implementation UITabBarController (CCAdditions)

- (void) setBackgroundImage:(UIImage *)i {
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
    imageView.backgroundColor = [UIColor colorWithPatternImage:i];  
    [[self view] addSubview:imageView];
    [[self view] sendSubviewToBack:imageView];
    [[self view] setOpaque:NO];
    [[self view] setBackgroundColor:[UIColor clearColor]];
    [imageView release];
}

@end
//example use in an apdelegate
#import "UITabBarController+CCAdditions.h"


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [tabBarController setBackgroundImage:[UIImage imageNamed:@"icon.png"]];
    [tabBarController.view setNeedsDisplay];
    return YES;
}
I use colorWithPatternImage instead of backgroundImage because it allows tiling when necessary

L1AppAppDelegate *theDelegate = (L1AppAppDelegate*)[[UIApplication sharedApplication] delegate]; tabBarController = theDelegate.tabBarController; tabBarController.selectedIndex = 1;


self.tabBarController.selectedViewController = YOURTABBARITEMController; self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
Do NOT forget to declare YOURTABBARController in the interface (.h), synthesize it, and #import the interface file into your .m file.
Plus for me I MYTABBARController was declared as @class in the interface too.

#pragma mark -
#pragma mark YouTube

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
    NSString *embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" autoplay=\"1\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
    NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    videoView.delegate = self;
    [videoView loadHTMLString:html baseURL:nil];
    [window addSubview:videoView];
    [videoView release];
}

// 웹뷰의 유튜브 재싱 버튼 클릭.
- (UIButton *)findButtonInView:(UIView *)view {
    UIButton *button = nil;
    if ([view isMemberOfClass:[UIButton class]]) {
        return (UIButton *)view;   
    }
    if (view.subviews && [view.subviews count] > 0) {
        for (UIView *subview in view.subviews) {
            button = [self findButtonInView:subview];
            if (button) return button;   
        }   
    }
    return button;   
}

// 웹뷰가 로드된 후 오토플레이 강제 처리.

- (void)webViewDidFinishLoad:(UIWebView *)_webView {
    UIButton *b = [self findButtonInView:_webView];
    [b sendActionsForControlEvents:UIControlEventTouchUpInside];
}




저번에 발표한 Core Data 쪽 보다가 NSPredicate란 넘이 있길래 Core Data관련으로만 쓰이는 줄 알았는데 아니군요.

NSArray 나 NSSet 필터링 하는데나.... NSObject 확인하는데도 쓰일 수 있네요

우선 NSArray 필터링 하는걸 간단하게 하나 보자면 아래와 같은 경우가 되겠네요

    NSString *string1 = @"a";
    NSString *string2 = @"b";
    NSString *string3 = @"c";
    NSString *string4 = @"d";
    NSString *string5 = @"e";
    NSString *string6 = @"f";
   
    NSArray *stringArray = [[NSArray alloc] initWithObjects:string1,
                                                    string2,
                                                    string3,
                                                    string4,
                                                    string5,
                                                    string6, nil];
    NSLog(@"%@", stringArray);
   
    NSPredicate *aPredicate = [NSPredicate predicateWithFormat:@"SELF  IN {'b', 'c', 'd', 'f'}"];
   
    NSArray *filteredArray = [stringArray filteredArrayUsingPredicate:aPredicate];
   
    NSLog(@"%@", filteredArray);

Array를 일일이 비교할 필요없이 한방에 추려내는게 가능하네요

NSObject 가 Predicate 충족하는가 확인하는 거는

    BOOL isExpectedObject = [aPredicate evaluateWithObject:string2];
   
    NSLog(@"%@", isExpectedObject?@"YES":@"NO");

이렇게 적용해 볼 수 있구요.

비교적 간단하게 Collection 필터링하는게 가능하니 유용할 것 같네요.
오브젝트에 관한 쿼리를 만든다고나 할까....
좀더 다양한 기능을 포함하고 있으니 관심있으신 분들은
개발자 문서 Predicate Programming Guide 그리고 NSPredicate Class Reference 참조하시기 바랍니다.


반응형