码迷,mamicode.com
首页 > 移动开发 > 详细

ios UI实现技巧

时间:2014-10-14 16:03:28      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

  1. statusBar 移动位置
    NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72} length:9] encoding:NSASCIIStringEncoding];
      key = @"statusBar";//一样的效果
       id object = [UIApplication sharedApplication];
       UIView *statusBar;
       if ([object respondsToSelector:NSSelectorFromString(key)]) {
           statusBar = [object valueForKey:key];
       }
       statusBar.transform = CGAffineTransformMakeTranslation(self.paneView.frame.origin.x, self.paneView.frame.origin.y);

     

  2. tabBar 自定义的图标
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
                        UIImage *icon = [[UIImage imageNamed:@"jinghua-selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
                        UIImage *unIcon = [[UIImage imageNamed:@"jinghua"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
                        [nc.tabBarItem setFinishedSelectedImage:icon withFinishedUnselectedImage:unIcon];
                    } else {
                        [nc.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"jinghua-selected"] withFinishedUnselectedImage:[UIImage imageNamed:@"jinghua"]];
                    }
                    [nc.tabBarItem setTitle:NSLocalizedString(@"精华", nil)];

     

  3. tabBarItem 自定义颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor colorWithWhite:113./255 alpha:1], UITextAttributeTextColor, nil]
                                                 forState:UIControlStateNormal];
    
        //Item选中状态颜色
        [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor colorWithWhite:56./255 alpha:1], UITextAttributeTextColor, nil]
                                                 forState:UIControlStateSelected];

     

  4. 扩展点击区域
    #import <objc/runtime.h>
    @implementation UIControl (userInteractoinEdgeInsets)
    static char topNameKey;
    static char rightNameKey;
    static char bottomNameKey;
    static char leftNameKey;
    
    -(void)setUserInteractionEdgeInsets:(UIEdgeInsets)edgeInsets{
        objc_setAssociatedObject(self, &topNameKey, [NSNumber numberWithFloat:edgeInsets.top], OBJC_ASSOCIATION_COPY_NONATOMIC);
        objc_setAssociatedObject(self, &rightNameKey, [NSNumber numberWithFloat:edgeInsets.right], OBJC_ASSOCIATION_COPY_NONATOMIC);
        objc_setAssociatedObject(self, &bottomNameKey, [NSNumber numberWithFloat:edgeInsets.bottom], OBJC_ASSOCIATION_COPY_NONATOMIC);
        objc_setAssociatedObject(self, &leftNameKey, [NSNumber numberWithFloat:edgeInsets.left], OBJC_ASSOCIATION_COPY_NONATOMIC);
    }
    
    - (CGRect)enlargedRect
    {
        NSNumber* topEdge = objc_getAssociatedObject(self, &topNameKey);
        NSNumber* rightEdge = objc_getAssociatedObject(self, &rightNameKey);
        NSNumber* bottomEdge = objc_getAssociatedObject(self, &bottomNameKey);
        NSNumber* leftEdge = objc_getAssociatedObject(self, &leftNameKey);
        if (topEdge && rightEdge && bottomEdge && leftEdge)
        {
            return CGRectMake(self.bounds.origin.x - leftEdge.floatValue,
                              self.bounds.origin.y - topEdge.floatValue,
                              self.bounds.size.width + leftEdge.floatValue + rightEdge.floatValue,
                              self.bounds.size.height + topEdge.floatValue + bottomEdge.floatValue);
        }
        else
        {
            return self.bounds;
        }
    }
    
    - (UIView*)hitTest:(CGPoint) point withEvent:(UIEvent*) event
    {
        CGRect rect = [self enlargedRect];
        if (CGRectEqualToRect(rect, self.bounds))
        {
            return [super hitTest:point withEvent:event];
        }
        return CGRectContainsPoint(rect, point) ? self : nil;
    }
    
    @end

     

  5. tabBarController 动态添加删除
    @implementation UITabBarController (dynamic)
    -(void)deleteChildViewController:(UIViewController*)controller{
        if ([self.viewControllers containsObject:controller]){
            NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.viewControllers];
            [viewControllers removeObject:controller];
            self.viewControllers = [NSArray arrayWithArray:viewControllers];
        }
    }
    
    -(void)insertChildViewController:(UIViewController*)controller atIndex:(NSInteger)index{
        if (index >=0 && index <=self.viewControllers.count && ![self.viewControllers containsObject:controller]) {
            NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.viewControllers];
            if (!viewControllers) {
                viewControllers = [NSMutableArray array];
            }
            [viewControllers insertObject:controller atIndex:index];
            self.viewControllers = [NSArray arrayWithArray:viewControllers];
        }
    }
    @end

     

  6. navigationBar 自定义
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, nil]];
    
        if ([[UIDevice currentDevice].systemVersion floatValue]<7.0) {
            [self.navigationBar setTintColor:[UIColor colorWithRed:0.0 green:194./255 blue:196./255 alpha:1]];
        }else{
            [self.navigationBar setBarTintColor:[UIColor colorWithRed:0.0 green:194./255 blue:196./255 alpha:1]];
        }

     

  7. 本地语言修改
    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:language, nil]
                                                  forKey:@"AppleLanguages"];
    
        [[NSUserDefaults standardUserDefaults] synchronize];

     

  8. 2
  9. 2
  10. 2
  11. 2
  12. 22
  13. 2
  14. 2
  15. 2
  16. 22
  17. 333
  18. 3
  19. 33
  20. 3
  21. 3
  22. 3333
  23. 3
  24. 3

ios UI实现技巧

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/liyufeng2013/p/4024383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!