关于一些小问题的总结

1.关于如何修改App名

有时我们想要xcode运行出的App名称与工程名不同,这时我们可以通过以下两种方式进行修改

  1. 通过修改plist文件的Bundle name项修改App名称
  2. 通过点击项目,进入info选项修改Bundle name

2.设置TabBarController上的图片,默认是蓝色的如何修改

  1. 为什么TabBar的selectedImage会变成蓝色:因为xcode会对它进行一个默认的蓝色渲染

  2. 如何改变,不让它默认渲染

    • 改变图片的渲染方式
    UIImage *image = [UIImage imageNamed:@"tabBarImage.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ctrl.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    ctrl.tabBarItem.selectedImage = image;`
    
    typedef NS_ENUM(NSInteger, UIImageRenderingMode) {
    UIImageRenderingModeAutomatic,          // Use the default rendering mode for the context where the image is used
    
    UIImageRenderingModeAlwaysOriginal,     // Always draw the original image, without treating it as a template
    UIImageRenderingModeAlwaysTemplate,     // Always draw the image as a template image, ignoring its color information
    

} NS_ENUM_AVAILABLE_IOS(7_0);

```
还有一种方式,就是在Asserts中直接修改图片的Render as 属性,这样做避免了写大量的代码,而且可以一劳永逸

3为什么要自定义TabBarController

4TabBar上的文字颜色如何修改

ctrl.tabBarItem 没有可以修改文字颜色的方法,于是我们在它的父类UIBarItem中找到了设置文字颜色的方法

- (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

凡是带有UI_APPEARANCE_SELECTOR这个宏的方法都可以拿到Appearance来统一设置

[[UITabBarItem appearance] setTitleTextAttributes:attrs forState:UIControlStateNormal];

5.设置视图控制器的title注意事项

self.title 相当于做了两件事,会同时做以下的修改

1 .self.navigationItem.title = @"ControllerName";
2 .self.tabBarItem.title = @"ControllerName";

6.如何修改导航控制器的返回按钮

这里用到的方法就是拦截导航控制器的push方法来设置, 拦截的方法还在单例中用到
方法是自定义导航控制器重写push方法

7.关于+ (void)initialize 方法的调用问题

+ (void)initialize 方法会在类第一次被调用时执行一次,并只执行一次

8.如何设置一个xib属于某个控制器

点击xib文件 -> PlaceHolders -> File's Owner ->class

这里曾经遇到过问题:

错误原因是:

reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ZDZFriendTrendsViewController" nib but the view outlet was not set.'

这里的出现问题的原因是不小心删除了File'Owner与xib中的view的关联关系
重新建立关系就可以解决问题

9.关于xib文件中UILaber的文字换行问题

使用option+enter键进行换行...

原文地址:https://www.cnblogs.com/denz/p/5303458.html