国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 11 使用兩種方法替換(Method Swizzling)去掉導航欄返回按鈕的文字

2019-10-21 18:41:15
字體:
來源:轉載
供稿:網友

  方法一:設置BarButtonItem的文本樣式為透明顏色,代碼如下:

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

   此外這種方法會導致title不能居中,被偏移很多,如下所示(雖然不被顯示,也占了導航欄左邊很大一部分位置)

ios,去掉,導航欄

     方法二:給UIViewController添加類別,然后在load方法里面用Method Swzilling方法替換 交換ViewDidAppear,部分代碼如下

+(void)load {  swizzleMethod([self class], @selector(viewDidAppear:), @selector(ac_viewDidAppear));}- (void)ac_viewDidAppear{  self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]                       initWithTitle:@""                       style:UIBarButtonItemStylePlain                       target:self                       action:nil];  [self ac_viewDidAppear];}void swizzleMethod(Class class, SEL originalSelector, SEL swizzledSelector){  // the method might not exist in the class, but in its superclass  Method originalMethod = class_getInstanceMethod(class, originalSelector);  Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);  // class_addMethod will fail if original method already exists  BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));  // the method doesn't exist and we just added one  if (didAddMethod) {    class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));  }  else {    method_exchangeImplementations(originalMethod, swizzledMethod);  }}

注意事項:

要給整個backButtonItem賦值才可以,
注:相關教程知識閱讀請移步到IOS開發頻道。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 伊宁县| 苗栗市| 怀安县| 秦皇岛市| 渝北区| 仙游县| 永修县| 长沙市| 吉水县| 安阳市| 淳安县| 肇庆市| 苏尼特右旗| 石棉县| 丰县| 阿拉善盟| 开原市| 丰顺县| 塘沽区| 玉树县| 新郑市| 南江县| 府谷县| 蒙阴县| 永年县| 正宁县| 宁海县| 金寨县| 明溪县| 杨浦区| 农安县| 清徐县| 乐山市| 武山县| 思南县| 秦皇岛市| 察哈| 永安市| 南汇区| 老河口市| 凤庆县|