`
zl4393753
  • 浏览: 332683 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

ios5 Appearance

 
阅读更多
Since iOS 5 as a developer you can finally change the tint/design of some elements without much trouble. Changing the background of your UINavigationBar just became so much easier.

@selector(appearance)

The classes that support the UIAppearance protocol have access to an appearance selector. This returns the appearance proxy for the receiver.

It’s on this proxy that you can call selectors like setTintColor:, setBackgroundImage:forBarMetrics:, etc…

Here is a list of classes that are supported:

UIActivityIndicatorView
UIBarButtonItem
UIBarItem
UINavigationBar
UIPopoverController
UIProgressView
UISearchBar
UISegmentedControl
UISlider
UISwitch
UITabBar
UITabBarItem
UIToolbar
UIView
UIViewController
Change the navigation bar background

Here is a quick example how you can easily set the background image of a navigation bar for the whole application.

Add the following line of code to your application:didFinishLaunchingWithOptions: in your AppDelegate:

[[UINavigationBar appearance]
setBackgroundImage:[UIImage imageNamed:@"navbar.png"]
forBarMetrics:UIBarMetricsDefault];
This will set the navbar.png image as a background on your navigation bar for all the navigation bars in your application.

Appearance depending on containment

But what if you want your popover to have the default blue UINavigationBar, but you just changed the appearance for the application. Than you can add this line of code:

[[UINavigationBar appearanceWhenContainedIn:
[UIPopoverController class], nil]
setBackgroundImage:nil
forBarMetrics:UIBarMetricsDefault];
When the UINavigationBar is used inside a UIPopoverController, then the background image for the navigation bar will be nil, and therefore the default background will be shown.

You can use UIPopoverController, your custom UIViewController classes, etc… as the containment classes.

What selectors are available on a class

How to find out which selectors can be accessed by the appearance proxy? Just go to XCode and go to the header file of a class, for example UINavigationBar.

In this header file you find the methods supported by the proxy by searching for the UI_APPEARANCE_SELECTOR constant. This is located behind the method definition.

You notice that the UINavigationBar appearance proxy supports the following selectors:

tintColor
setTintColor:
setBackgroundImage:forBarMetrics:
backgroundImageForBarMetrics:
titleTextAttributes
setTitleTextAttributes:
setTitleVerticalPositionAdjustment:forBarMetrics:
titleVerticalPositionAdjustmentForBarMetrics:
分享到:
评论

相关推荐

    ios开发小技巧

    [theImage drawInRect:CGRectMake(5, 5, theSize.width-10, theSize.height-20)];//这个地方的大小要自己调整,以适应alertview的背景颜色的大小。 theImage = UIGraphicsGetImageFromCurrentImageContext(); ...

    iOS 隐藏导航条和状态栏实现方法

    iOS 隐藏导航条和状态栏实现方法 状态栏的高度是20,导航栏的高度是44,如果同时存在状态栏的导航条,我们通常会设置view上的控件的位置的X 大于等于 64. 一:隐藏导航条:self.navigationController....

    react-native-appearance:在iOS,Android和Web上访问操作系统外观信息(当前仅亮暗模式)

    React本色 在iOS,Android和Web上访问操作系统外观信息。...expo install react-native-appearance 然后,在app.json中,包括"userInterfaceStyle"以侦听设备的外观设置: { "expo" : { /* Supported user interfa

    iOS7用户界面过渡指南

    支持 iOS 6 系统 UI 上的更新 布局和外观 ( Layout & Appearance ) 操作栏和栏上按钮 ( Bars & Bar Buttons ) 内容视图 ( Content View ) 控件(Controls ) 临时视图 ( Temporary Views ) 文档修订历史

    ios-KSDatePicker.zip

    picker.appearance.radius = 5; //设置回调 picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){ if (buttonType == ...

    ios自定义程序锁屏功能

    ios自定义程序锁屏功能源码,源码ABPadLockScreen,该源码可以支持自定义程序锁屏的,如在ipad中的一些应用都已经采用了该功能来实现锁屏的,ABPadLockScreen可实现了一个通用的解决方案,特别是对实现对app的锁定等...

    IOS 改变键盘颜色代码

    IOS 改变键盘颜色的代码 iPhone和iPod touch的键盘颜色其实是可以通过代码更改的,这样能更匹配App的界面风格,下面是改变iPhone键盘颜色的代码。 1、只有Number Pad和Phone Pad这两种数字键盘才有效果 2、设置...

    iOS中状态栏的基本使用方法汇总

    一、状态栏与导航栏 状态栏:显示时间、电池等信息 导航栏:显示app页面标题,返回按钮等 iOS7之前:状态栏与导航栏是...通过修改info.plist中的View controller-based status bar appearance属性为NO或者YES,状态栏

    DarkModeSplashScreen:用Xamarin编写的适用于iOS和Android的示例应用程序。表格显示了如何实现深色模式的启动页面

    暗模式启动画面 现在,iOS 13和Android Q支持黑暗模式,我们也希望应用程序的启动画面也变黑。 此示例演示如何创建一个启动屏幕,当...iOS Dark Appearance已禁用 启用了Android Dark主题 Android Dark Theme Disabled

    TTToast:这是一个适用于iOS的简单的Toast库

    TT吐司 Swift编写的一个简单的Toast库安装可可豆通过将以下内容添加到Podfile来与CocoaPods一起安装: platform :ios , '8.0'pod 'TTToast'手动地手动添加: 将TTToast.swift添加到您的项目。 链接QuartzCore。例子 ...

    iOS开发技巧之状态栏字体颜色的设置方法

    一、在info.plist中,将View controller-based status bar appearance设为NO 状态栏字体的颜色只由下面的属性设定,默认为白色: // default is UIStatusBarStyleDefault [UIApplication sharedApplication]....

    详解移动端HTML5页面端去掉input输入框的白色背景和边框(兼容Android和ios)

    ),在iOS上面背景色和边框都没有了,但是在andriod上边框和背景色还是存在。后来加上样式FILTER: alpha(opacity=0),在andriod中就去掉了边框和背景。 去掉背景和边框比以前好看多了,但是因为类型是date,所以右边...

    iOS中导航栏的基本使用汇总

    一、设置导航栏样式 设置导航栏的样式可分为全局设置与局部设置; 1.全局设置 ...[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@navigationBarImg] forBarMetrics:UIBarMet

    关于iOS中的各种颜色设置总结大全(推荐)

    前言 最近因为工作的原因,在做界面的时候,有时会忘记某种控件的颜色怎么设置,需要去网上进行搜索,所以写下这篇文章。...[[UINavigationBar appearance] setTitleTextAttributes: @{NSForeground

    iOS 11 使用两种方法替换(Method Swizzling)去掉导航栏返回按钮的文字

    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal]; [[UIBarButtonItem appearance] setTitleTextAttributes:@{...

    ARGraphs:适用于 iOS 的有趣图表

    适用于 iOS 的有趣图表。 所有图表都响应外观选择器,因此您可以在应用程序完成启动中设置应用程序范围设置。 // Line Graph [[ARLineGraph appearance ] setUseBackgroundGradient: NO ]; [[ARLineGraph ...

    Sketch47破解版.永久使用.

    The “iOS UI Design” document is now a built-in Library, updated for iOS 11 and iPhone X, and makes use of our new Smooth Corners feature Individual layers can now be exported using the Command-E ...

    移动端HTML5 input常见问题(小结)

    -webkit-appearance: none; border-radius: 0; } 2. 焦点在 input 时,placeholder 没有隐藏 input:focus::-webkit-input-placeholder{ opacity: 0; } 3. input 输入框调出数字键盘 单独使用type=number时,...

    JXGradientNavigationBar:iOS上具有渐变颜色的自定义UINavigationBar子类

    JXGradientNavigationBar ...[JXGradientNavigationBar appearance ].barTintGradientColors = @[[UIColor greenColor ], [UIColor yellowColor ]]; 自定义导航控制器: UINavigationController * navigationControl

Global site tag (gtag.js) - Google Analytics