博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios UI实现技巧
阅读量:5351 次
发布时间:2019-06-15

本文共 6145 字,大约阅读时间需要 20 分钟。

  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 
    @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. UITableView控制表格线

    -(void)viewDidLayoutSubviews{    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];    }        if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];    }}-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } }

     

  9. UItableView 中或是其superview 中有 tap 事件时 tableView 不响应 tableVeiw:didSelectedRowAtIndex: 方法
  10.  

转载于:https://www.cnblogs.com/liyufeng2013/p/4024383.html

你可能感兴趣的文章
组合数学 UVa 11538 Chess Queen
查看>>
oracle job
查看>>
Redis常用命令
查看>>
[转载]电脑小绝技
查看>>
windos系统定时执行批处理文件(bat文件)
查看>>
thinkphp如何实现伪静态
查看>>
BZOJ 2243: [SDOI2011]染色( 树链剖分 )
查看>>
BZOJ 1925: [Sdoi2010]地精部落( dp )
查看>>
c++中的string常用函数用法总结!
查看>>
[DLX精确覆盖+打表] hdu 2518 Dominoes
查看>>
SuperMap iServerJava 6R扩展领域开发及压力测试---判断点在那个面内(1)
查看>>
Week03-面向对象入门
查看>>
一个控制台程序,模拟机器人对话
查看>>
Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(上篇——纯前端多页面)
查看>>
我的PHP学习之路
查看>>
【题解】luogu p2340 奶牛会展
查看>>
对PostgreSQL的 SPI_prepare 的理解。
查看>>
解决响应式布局下兼容性的问题
查看>>
使用DBCP连接池对连接进行管理
查看>>
【洛谷】【堆+模拟】P2278 操作系统
查看>>