#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UIInterface.h>
#import <UIKit/UIFont.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UIBarCommon.h>
#import <UIKit/UINavigationItem.h>
導(dǎo)入某個(gè)框架的某個(gè)頭文件,說明在這里面需要用到
NS_ASSUME_NONNULL_BEGIN
@class UINavigationItem, UIBarButtonItem, UIImage, UIColor;
// 引入其他類,或者協(xié)議,需要用到的
@protocol UINavigationBarDelegate;
NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationBar : UIView <NSCoding, UIBarPositioning>
@property(nonatomic,assign) UIBarStyle barStyle UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
@property(nullable,nonatomic,weak) id<UINavigationBarDelegate> delegate;
/*
New behavior on iOS 7.
Default is YES.
You may force an opaque background by setting the property to NO.
If the navigation bar has a custom background image, the default is inferred
from the alpha values of the image—YES if it has any pixel with alpha < 1.0
If you send setTranslucent:YES to a bar with an opaque custom background image
it will apply a system opacity less than 1.0 to the image.
If you send setTranslucent:NO to a bar with a translucent custom background image
it will provide an opaque background for the image using the bar's barTintColor if defined, or black
for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
iOS 7新添加的行為。
默認(rèn)為YES。
您可以通過將屬性設(shè)置為NO來強(qiáng)制使用不透明背景。
被動(dòng)設(shè)置:
1.如果導(dǎo)航欄設(shè)置了自定義背景圖像,則會(huì)推斷出該屬性的默認(rèn)值從圖像的alpha值
如果圖像中有alpha <1.0的任何像素,則開始該屬性被設(shè)置為YES,
- 釋義:如果導(dǎo)航欄設(shè)置了一張自定義圖片,那么只要這個(gè)圖片中,有一個(gè)像素點(diǎn)透明度小于1,那么該屬性將被設(shè)置為YES,即半透明。
主動(dòng)設(shè)置:
2. 如果您通過 ”setTranslucent:YES “方法將導(dǎo)航欄設(shè)置為半透明,并且這個(gè)導(dǎo)航欄已經(jīng)設(shè)置了一張不透明背景圖像,
它會(huì)將小于1.0的系統(tǒng)不透明度應(yīng)用于圖像。
- 釋義:如果你將該屬性設(shè)為YES,并且這個(gè)導(dǎo)航欄已經(jīng)設(shè)置了一張不透明的背景圖片(即圖片中的每一個(gè)像素點(diǎn)的alpha值,都為1),那么該背景圖片的透明杜,即alpha將會(huì)小于1,被隨機(jī)設(shè)置為一個(gè)系統(tǒng)的不透明度。
3.如果您通過setTranslucent:NO方法將導(dǎo)航欄設(shè)置為不透明,并且這個(gè)導(dǎo)航欄已經(jīng)設(shè)置了一張半透明背景圖像,
它將使用條形圖的barTintColor(如果已定義)或黑色為圖像提供不透明背景
如果barTintColor為nil,則為UIBarStyleBlack或白色為UIBarStyleDefault。
- 釋義:一旦設(shè)置為NO,就是不透明
總結(jié):如果是被動(dòng)設(shè)置,如果圖片的alpha小于< 1,那么該屬性值就是YES,除非是1,值為NO,
如果是主動(dòng)設(shè)置,不管設(shè)置的背景圖片的alpha是否為1,如果該屬性值為YES, 那么導(dǎo)航欄就是半透明,如果該屬性值為NO,那么導(dǎo)航欄為YES。
*/
// 半透明
@property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
// iOS 6及更早版本的默認(rèn)值為NO。 如果barStyle設(shè)置為UIBarStyleBlackTranslucent,則始終為YES
// Pushing a navigation item displays the item's title in the center of the navigation bar.
// The previous top navigation item (if it exists) is displayed as a "back" button on the left.
- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated;
- (nullable UINavigationItem *)popNavigationItemAnimated:(BOOL)animated; // Returns the item that was popped.
@property(nullable, nonatomic,readonly,strong) UINavigationItem *topItem;
@property(nullable, nonatomic,readonly,strong) UINavigationItem *backItem;
@property(nullable,nonatomic,copy) NSArray<UINavigationItem *> *items;
- (void)setItems:(nullable NSArray<UINavigationItem *> *)items animated:(BOOL)animated; // If animated is YES, then simulate a push or pop depending on whether the new top item was previously in the stack.
// 如果動(dòng)畫為YES,則根據(jù)新的頂級(jí)項(xiàng)目是否先前位于堆棧中來模擬push或pop。
/// When set to YES, the navigation bar will use a larger out-of-line title view when requested by the current navigation item. To specify when the large out-of-line title view appears, see UINavigationItem.largeTitleDisplayMode. Defaults to NO.
// 設(shè)置為YES時(shí),導(dǎo)航欄將在當(dāng)前導(dǎo)航項(xiàng)請(qǐng)求時(shí)使用更大的外線標(biāo)題視圖。 要指定何時(shí)顯示大的外部標(biāo)題視圖,請(qǐng)參閱UINavigationItem.largeTitleDisplayMode。 默認(rèn)為NO。
@property (nonatomic, readwrite, assign) BOOL prefersLargeTitles UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
/*
The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background
and behaves as described for the tintColor property added to UIView.
To tint the bar's background, please use -barTintColor.
在iOS 7.0上,tintColor對(duì)導(dǎo)航欄的行為已經(jīng)改變。 它不再影響導(dǎo)航欄的背景
行為與添加到UIView的tintColor屬性的描述相同。
要為導(dǎo)航欄的背景著色,請(qǐng)使用-barTintColor。
*/
@property(null_resettable, nonatomic,strong) UIColor *tintColor;
@property(nullable, nonatomic,strong) UIColor *barTintColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // default is nil
/* In general, you should specify a value for the normal state to be used by other states which don't have a custom value set.
Similarly, when a property is dependent on the bar metrics (on the iPhone in landscape orientation, bars have a different height from standard), be sure to specify a value for UIBarMetricsDefault.
通常,您應(yīng)該為沒有自定義值集的其他狀態(tài)指定正常狀態(tài)的值。
同樣,當(dāng)屬性依賴于條形度量標(biāo)準(zhǔn)時(shí)(在橫向方向上的iPhone上,條形圖與標(biāo)準(zhǔn)高度不同),請(qǐng)確保為UIBarMetricsDefault指定值。
*/
- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forBarPosition:(UIBarPosition)barPosition barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage *)backgroundImageForBarPosition:(UIBarPosition)barPosition barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
/*
Same as using UIBarPositionAny in -setBackgroundImage:forBarPosition:barMetrics. Resizable images will be stretched
vertically if necessary when the navigation bar is in the position UIBarPositionTopAttached.
與在-setBackgroundImage中使用UIBarPositionAny相同:forBarPosition:barMetrics。 可調(diào)整大小的圖像將被拉伸
如果需要,當(dāng)導(dǎo)航欄位于UIBarPositionTopAttached位置時(shí)垂直。
*/
- (void)setBackgroundImage:(nullable UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (nullable UIImage *)backgroundImageForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
/* Default is nil. When non-nil, a custom shadow image to show instead of the default shadow image. For a custom shadow to be shown, a custom background image must also be set with -setBackgroundImage:forBarMetrics: (if the default background image is used, the default shadow image will be used).
默認(rèn)值為零。 當(dāng)非零時(shí),顯示自定義陰影圖像而不是默認(rèn)陰影圖像。 要顯示自定義陰影,還必須使用-setBackgroundImage設(shè)置自定義背景圖像:forBarMetrics :(如果使用默認(rèn)背景圖像,將使用默認(rèn)陰影圖像)。
*/
@property(nullable, nonatomic,strong) UIImage *shadowImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
/* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.
您可以使用NSAttributedString.h中的鍵在文本屬性字典中指定標(biāo)題的字體,文本顏色和陰影屬性。
*/
@property(nullable,nonatomic,copy) NSDictionary<NSAttributedStringKey, id> *titleTextAttributes NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
/* You may specify the font, text color, and shadow properties for the large title in the text attributes dictionary, using the keys found in NSAttributedString.h.
*/
@property(nullable, nonatomic, copy) NSDictionary<NSAttributedStringKey, id> *largeTitleTextAttributes UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
- (void)setTitleVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
- (CGFloat)titleVerticalPositionAdjustmentForBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
/*
The back indicator image is shown beside the back button.
The back indicator transition mask image is used as a mask for content during push and pop transitions
Note: These properties must both be set if you want to customize the back indicator image.
后退指示圖像顯示在后退按鈕旁邊。
后指示符轉(zhuǎn)換掩碼圖像在推送和彈出轉(zhuǎn)換期間用作內(nèi)容的掩碼
注意:如果要自定義后指示圖像,則必須同時(shí)設(shè)置這些屬性。
*/
@property(nullable,nonatomic,strong) UIImage *backIndicatorImage NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
@property(nullable,nonatomic,strong) UIImage *backIndicatorTransitionMaskImage NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
@end
@protocol UINavigationBarDelegate <UIBarPositioningDelegate>
@optional
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item; // called to push. return NO not to.
- (void)navigationBar:(UINavigationBar *)navigationBar didPushItem:(UINavigationItem *)item; // called at end of animation of push or immediately if not animated
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item; // same as push methods
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item;
@end
NS_ASSUME_NONNULL_END
#else
#import <UIKitCore/UINavigationBar.h>
#endif
UINavigationBar
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 轉(zhuǎn)載于:http://www.cocoachina.com/ios/20150409/11505.html來源:G...
- UINavigationController相關(guān) 概述 UINavigationController繼承自UIVi...
- 我開發(fā)的時(shí)候遇到一個(gè)問題就是你無論如何設(shè)置navigationBar.tintColor在Hierarchy中始終...
- 1.iOS7之后 要想改變navigationbar的顏色 可以這樣子改 self.navigationContr...
- iOS11 真的是太坑了,界面偏移什么的都是小事,最頭疼的是 iPhone X,狀態(tài)欄 44 什么鬼,tabbar...