• 主页
  • 关于我
    • DSL'Blog photo

      DSL'Blog

      我叫董诗磊,我就是一码农.欢迎来到我的博客

    • 了解更多
    • Email
    • Github
  • 文章
    • 所有文章
    • 所有标签

iOS随手记(一)

02 Apr 2017

Reading time ~1 minute

开发随手记(一)


1.关于给tabbarItem设置属性

1.1设置图片

childController.tabBarItem.image= [normalImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

childController.tabBarItem.selectedImage= [selectedImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

1.2未选中字体颜色

[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:unselectColor,NSFontAttributeName:[UIFont fontWithName:foneName size:15]} forState:UIControlStateNormal];

1.3选中字体颜色

[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:selectColor,NSFontAttributeName:[UIFont fontWithName:foneName size:15]} forState:UIControlStateSelected];

2.之前在做项目的时候在push界面的时候总是发现有灰色的阴影。在网上查了资料在知道

自从iOS7之后push导航栏出现白色阴影,导航栏的背景色是透明的,或者是黑色阴影估计就是底层Controller的背景色的解决方法是
self.window.backgroundColor = [UIColor whiteColor];

3.关于通知的注意事项

3.1在主线程上发送通知

3.2注册通知和移除通知一定要成对出现,比如在

//一定要成对出现,避免出现bug
- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NSNotificationCenterAction) name:@"NSNotificationCenter"object:nil];

}

- (void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSNotificationCenter"object:nil];

}

3.3在通知移除的时候。不要使用

[[NSNotificationCenter defaultCenter] removeObserver:self]
因为上面那个方法可能会把系统注册的通知也给移除了,不要这样操纵,一旦出现bug。不容易发现。正确的移除方式是
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSNotificationCenter"object:nil];

4.获取文件的扩展名

NSString *str  = @"DSL.mp4";

BOOL isMp4 = [str hasSuffix:@".mp4"];

//拿到字符串扩展名

NSString *extension = [str pathExtension];

if ([extension isEqualToString:@"mp4"]) {

NSLog(@"我是MP4");

}

4.获取cell上的控件

- (void)digAction:(UIButton*)btn event:(id)event

{

NSSet*touches =[eventallTouches];

UITouch*touch =[touchesanyObject];

CGPointcurrentTouchPosition = [touchlocationInView:_tableView];

NSIndexPath*indexPath= [_tableViewindexPathForRowAtPoint:currentTouchPosition];

//通过这个index获取cell

}

本篇结束了。。。