美文网首页iOSiOS旅途
iOS新建项目全局样式设置

iOS新建项目全局样式设置

作者: 朝阳小麦 | 来源:发表于2018-08-20 17:52 被阅读132次

    适用人群:iOS开发人员。
    本文内容:iOS新建工程需要的一些常用设置。

    1.去除返回按钮的文本显示:

    一般搭建项目,会建立BaseViewController,所有界面均继承自该父类,方便公用代码的添加。在该文件中加上如下代码去除返回文本:

    - (void)viewDidLoad {
        [super viewDidLoad];
        //去除返回按钮的文字显示
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" 
                      style:UIBarButtonItemStylePlain target:self action:nil];
    }
    

    2.设置返回按钮为图片样式:

    全局写法,一般写在AppDelegate文件中即可。

    UIImage *backImage = [[UIImage imageNamed:@"public_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [[UINavigationBar appearance] setBackIndicatorImage:backImage];
    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backImage];
    

    3.设置navigationTitle的色值、字号:

    全局写法,一般写在AppDelegate文件中即可。

    [[UINavigationBar appearance] setTitleTextAttributes:  @{ NSForegroundColorAttributeName:[UIColor whiteColor],
            NSFontAttributeName:[UIFont font18]}];
    

    4.设置navigationbar背景色:

    全局写法,一般写在AppDelegate文件中即可。

    [[UINavigationBar appearance] setBarTintColor:[UIColor themeColor]];
    

    5.设置UINavigationBar的显示颜色:

    全局写法,一般写在AppDelegate文件中即可。

    [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont font16],
            NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    

    6.如何设置view,坐标从状态栏开始?

    - (void)viewDidLoad {
        [super viewDidLoad];
        //本viewController中的ScrollView使用哪些新特性中提供的contentInsets.
        //默认为All,也就是所有的方向都使用
        self.edgesForExtendedLayout = UIRectEdgeNone;
        //表示这种自适应的contentInsets是否包括statusBar的高度。
        //我们的tableView之所以会向上滚动20像素就是因为当我们隐藏了statusBar之后scrollView认为没有了状态栏,那么它的contentInsets.top自动减小20px.
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        //表示在本viewController的view.subviews中的子view是否要受到系统的自动适配。
        //比如在这里如果设为YES(默认也是),那么这个tableView.contentInsets.top就会为64.
        //这里我们置为No,就不会又这个自动的调整了。
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    

    7.如果网络请求不是https,还需要在info.plist文件加上:

    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    
    

    相关文章

      网友评论

        本文标题:iOS新建项目全局样式设置

        本文链接:https://www.haomeiwen.com/subject/dkgliftx.html