statusBar--NavBar---CustomButton

http://www.cnblogs.com/ihojin/p/ios7-statusbarstyle-in-viewcontroller.html

重写NavBar在其他的文件里设置状态栏一直没有用,只有在NavBar设置才能用

In my iPhone application built with Xcode 5 for iOS 7 I set UIViewControllerBasedStatusBarAppearance=YES in info.plist, and in my ViewController I have this code:

-(UIStatusBarStyle) preferredStatusBarStyle{
    returnUIStatusBarStyleLightContent;
}还有在plsit里面设置就能用了

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

加入这段代码就可以了,

-----------------------------自定义button----------------------------

//  CustomButton.m

//  BuyInsurance

//  Created by 闪电 on 15/2/11.

//  Copyright (c) 2015年 No9527. All rights reserved.

#define TitleButtonImageW LENGTH_4INCH_ADAPTED(10)

#import "CustomButton.h"

@implementation CustomButton

- (id)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];

if (self) {

// Initialization code

// 文字颜色

[self setTitleColor:ColorI(0xffffff) forState:UIControlStateNormal];

// 高亮时不要让imageView变灰色

//        self.adjustsImageWhenHighlighted = NO;

self.imageView.contentMode = UIViewContentModeCenter;

// 设置文字右对齐

self.titleLabel.textAlignment = NSTextAlignmentLeft;

// 背景

self.titleLabel.font = FONT_4INCH_ADAPTED_WIDTH(16);

[self setTitleColor:ColorI(0xffffff) forState:UIControlStateNormal];

//        [self setTitleColor:ColorI(0xadadad) forState:UIControlStateHighlighted];

}

return self;

}

- (CGRect)imageRectForContentRect:(CGRect)contentRect{

CGFloat imageY = 0;

CGFloat imageW = TitleButtonImageW;

CGFloat imageX = 0;

CGFloat imageH = self.height;

return CGRectMake(imageX, imageY, imageW, imageH);

}

- (CGRect)titleRectForContentRect:(CGRect)contentRect

{

CGFloat titleX = TitleButtonImageW + LENGTH_4INCH_ADAPTED(5);

CGFloat titleY = 0;

CGFloat titleW = self.width - TitleButtonImageW;

CGFloat titleH = self.height;

return CGRectMake(titleX, titleY, titleW, titleH);

}

@end

------------------------------------重写NavBar------------------------

//

//  BaseNavViewController.m

//  BuyInsurance

//

//  Created by 闪电 on 15/2/11.

//  Copyright (c) 2015年 No9527. All rights reserved.

//

#import "BaseNavViewController.h"

#import "CustomButton.h"

@interface BaseNavViewController ()

@end

@implementation BaseNavViewController

+ (void)initialize{

// 设置导航栏主题

[self setupNavTheme];

}

#pragma mark - 设置导航栏主题

+ (void)setupNavTheme{

// 1.获得appearance对象

UINavigationBar *navBar = [UINavigationBar appearance];

// 设置背景

[navBar setBackgroundImage:[UIImage imageAutomaticName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];

// 设置文字

NSDictionary *textAtts =  [self setTitleTextFont:FONT_4INCH_ADAPTED_WIDTH(16) fontColor:[UIColor whiteColor]];

[navBar setTitleTextAttributes:textAtts];

}

// 状态栏

- (UIStatusBarStyle)preferredStatusBarStyle{

return UIStatusBarStyleLightContent;

}

// 设置文字

+ (NSDictionary *)setTitleTextFont:(UIFont *)font fontColor:(UIColor *)color{

NSMutableDictionary *textAtts = [NSMutableDictionary dictionary];

// 设置文字颜色

textAtts[NSForegroundColorAttributeName] = color;

// 去掉阴影

NSShadow *shadow = [[NSShadow alloc] init];

shadow.shadowOffset = CGSizeMake(0, 0);

shadow.shadowColor = color;

// 模糊度

shadow.shadowBlurRadius = 0;

textAtts[NSShadowAttributeName] = shadow;

// 设置字体

textAtts[NSFontAttributeName] = font;

return textAtts;

}

// 设置导航栏按钮主题

#pragma mark  设置导航栏按钮主题

+ (void)setupItemTheme{

// 1.获得appearance对象

UIBarButtonItem *item = [UIBarButtonItem appearance];

// 2.设置背景

// 设置文字

NSDictionary *AttrFont = [self setTitleTextFont:FONT_4INCH_ADAPTED_WIDTH(16) fontColor:[UIColor orangeColor]];

[item setTitleTextAttributes:AttrFont forState:UIControlStateNormal];

NSMutableDictionary *hightAttrFont =  [NSMutableDictionary dictionary];

hightAttrFont.dictionary = AttrFont;

hightAttrFont[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.3];

[item setTitleTextAttributes:hightAttrFont forState:UIControlStateHighlighted];

NSMutableDictionary *disabledlAttrFont =  [NSMutableDictionary dictionary];

disabledlAttrFont.dictionary = AttrFont;

disabledlAttrFont[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.2];

[item setTitleTextAttributes:hightAttrFont forState:UIControlStateDisabled];

}

- (void)viewDidLoad

{

[super viewDidLoad];

if (IOS7) { // ios 6 不支持

// 清空手势识别器的代理,就能恢复一起滑动移除控制器

self.interactivePopGestureRecognizer.delegate = nil;

}

//    [self statusBar];

}

- (void)statusBar{

UIView *statusBar = [[UIView alloc] initWithFrame:CGRectMake(0, -20, 0, 0)];

statusBar.size = [UIApplication sharedApplication].statusBarFrame.size;

[self.navigationBar addSubview:statusBar];

statusBar.backgroundColor = [UIColor yellowColor];

}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

{

if (self.viewControllers.count > 0) {

// 左上脚的返回按钮

NSInteger count = self.viewControllers.count - 1;

UIViewController *vc = self.viewControllers[count];

UIImage* backImage = [UIImage imageAutomaticName:@"arrow-left-default"];

CGRect backframe = CGRectMake(0,0,LENGTH_4INCH_ADAPTED(100),LENGTH_4INCH_ADAPTED(30));

CustomButton* backButton= [[CustomButton alloc] initWithFrame:backframe];

[backButton setImage:backImage forState:UIControlStateNormal];

//        backButton.backgroundColor = [UIColor yellowColor];

[backButton setTitle:vc.title forState:UIControlStateNormal];

//        backButton.imageEdgeInsets = UIEdgeInsetsMake(0, LENGTH_4INCH_ADAPTED(-30), 0, 0);

//        backButton.titleEdgeInsets = UIEdgeInsetsMake(0, LENGTH_4INCH_ADAPTED(-15), 0, 0);

backButton.titleLabel.font = FONT_4INCH_ADAPTED_WIDTH(16);

[backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

viewController.navigationItem.leftBarButtonItem = leftBarButtonItem;

}

[super pushViewController:viewController animated:animated];

}

/**

*  返回

*/

- (void)back

{

[self popViewControllerAnimated:YES];

}

@end

时间: 2024-11-05 16:26:53

statusBar--NavBar---CustomButton的相关文章

获取其他进程中StatusBar的文本

(*// 标题:获取其他进程中StatusBar的文本 说明:Window2000+Delphi6调试通过 设计:Zswang 支持:[email protected] 日期:2005-02-22 //*) uses CommCtrl; function GetStatusBarText(mHandle: THandle): string; var   vBuffer: array[0..$1000] of Char;   vSize: Integer;   I: Integer;   vCou

statusBar状态栏_03

iOS7 中的StatusBar和之前版本的相比发生了很大变化,在iOS7下对statusbar的使用需要全新的方法,现在就总结以下statusbar的方法: 样式 显示和隐藏 动画效果 默认无StatusBar 1. 样式 StatusBar有两种样式: UIStatusBarStyleDefault : UIStatusBarStyleLightContent 要改变StatusBar的显示样式需要在UIViewController中重载: - (UIStatusBarStyle)prefe

12 StatusBar

1 package com.szy.status; 2 3 import android.app.IntentService; 4 import android.app.Notification; 5 import android.app.NotificationManager; 6 import android.app.PendingIntent; 7 import android.content.Intent; 8 import android.util.Log; 9 10 /** 11 *

张高兴的 UWP 开发笔记:手机状态栏 StatusBar

UWP 有关应用标题栏 TitleBar 的文章比较多,但介绍 StatusBar 的却没几篇,在这里随便写写.状态栏 StatusBar 用法比较简单,花点心思稍微设计一下,对应用会是个很好的点缀. 说明一下,当应用运行在 PC 上时我们叫 TitleBar ,运行在 Mobile 上时我们叫 StatusBar ,这是两个不同的玩意儿. 在使用 StatusBar 之前,你需要在项目的引用里添加 Windows Mobile Extensions for the UWP ,并且引用 Wind

Android应用:StatusBar状态栏、NavigationBar虚拟按键栏、ActionBar标题栏、Window屏幕内容区域等的宽高

一.屏幕中各种栏目以及屏幕的尺寸 当我们需要计算屏幕中一些元素的高度时,或许需要先获取到屏幕或者各种栏目的高度,下面这个类包含了Status bar状态栏,Navigation bar虚拟按键栏,Action bar标题栏, Window屏幕内容等的宽高的计算,可以带来极大的方便. 因为我在代码中做了比较详尽的注释,在这里不再多阐述,以下是代码: 1 /** 2 * 这个类描述了当前设备的配置中system bar的尺寸(StatusBar状态栏,NavigationBar虚拟按键栏,Actio

StatusBar

iOS7 StatusBar 在需要隐藏或改变样式时在UIViewConroller中调用: [self setNeedsStatusBarAppearanceUpdate]; 1.隐藏 StatusBar在iOS7中无法使用一下接口隐藏: [[UIApplication sharedApplication] setStatusBarHidden:YES]; 若要隐藏需要在UIViewController中实现下列函数: - (BOOL)prefersStatusBarHidden { retu

How to change statusbar text color to dark on android 4.4

Because I haven't enough votes, so post picture at here, thank you. Almost 2 weeks ago, I was searching How to change the text color of the statusbar to dark color on android 4.4 The default text color is white, like this I'd like to change the topmo

iOS-实现映客首页TabBar和滑动隐藏NavBar和TabBar

之前在做直播的时候,参照了映客App,发现其首页的效果还挺不错,在网上找了一下相关仿映客App代码和博客,大部分都是说如何播放直播流和推流,对于UI这块甚少,所以我自己花了点时间研究了一下映客的首页UI效果. 转载自 SUN'S BLOG - 专注互联网知识,分享互联网精神! . 映客首页主要分两部分,一部分是实现没有文字而且中间按钮突出的TabBar,另一部分是显示滑动ScrollView隐藏和显示NavBar和TabBar.我们来慢慢看. 一.TabBar实现 首先,我们看下实现后的效果.

Android statusbar 透明后 toolbar与之重叠问题的解决方法

之前想要给statusbar和toolbar实现这样的效果: 为使得statusbar变为透明,在自定义theme中给statusbar添加了以下属性: <item name="android:windowTranslucentStatus">true</item> 可是在statusbar变透明后界面却变成下图这个样子:(即toolbar悬浮在statusbar之后) 为了说明情况,我用另一个更明显的界面来解释: 起初我简单粗暴的为toolbar加了一个mar

设置statusBar状态栏颜色

设置statusBar的[前景部分] 简单来说,就是设置显示电池电量.时间.网络部分标示的颜色, 这里只能设置两种颜色: 默认的黑色(UIStatusBarStyleDefault) 白色(UIStatusBarStyleLightContent) 可以设置的地方有两个:plist设置里面 和 程序代码里 1.plist设置statusBar 在plist里增加一行 UIStatusBarStyle(或者是“Status bar style”也可以),这里可以设置两个值,就是上面提到那两个 UI