Closed 13098806890 closed 7 years ago
same question
这种方法确实可能会有问题,不过你可以在一个 block 中配置颜色,DKNightVersion 会在每次改变主题时,调用 block
我是重写了updatecolor方法,可以丢子典型数据进去 发自网易邮箱大师 在2017年03月12日 21:10,Draveness 写道:
这种方法确实可能会有问题,不过你可以在一个 block 中配置颜色,DKNightVersion 会在每次改变主题时,调用 block
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
楼主解决了吗? 怎么不重写titleVIew改变nav title颜色呀
The only way to set self.navgitaionItem.title's color is to set TitleTextAttributes instead of the color. for example. NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor],NSForegroundColorAttributeName, nil]; [self.navigationController.navigationBar setTitleTextAttributes:dic]; self.navigationItem.title = @"theTitleIWantToChangeColor";
but the way you offer can;t solve this.
So, I overwrite the method - (void)night_updateColor in UINavigationBar+Night.m and add a property to support that, but this is just a temp way to solve this. Hope you offer a better way to solve this.
(DKColorPicker)dk_titleTintColorPicker { return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker)); }
(void)dk_setTitleTintColorPicker:(DKColorPicker)picker{ objc_setAssociatedObject(self, @selector(dk_titleTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); UIColor color = picker(self.dk_manager.themeVersion); NSDictionary navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [color copy],NSForegroundColorAttributeName, nil]; [self setTitleTextAttributes:navbarTitleTextAttributes]; [self.pickers setValue:[picker copy] forKey:@"setTitleTextAttributes:"]; }
(void)night_updateColor { [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString _Nonnull selector, DKColorPicker _Nonnull picker, BOOL _Nonnull stop) { SEL sel = NSSelectorFromString(selector); id result = ((DKColorPicker)picker)(self.dk_manager.themeVersion); if([selector isEqualToString:@"setTitleTextAttributes:"]) { result = [NSDictionary dictionaryWithObjectsAndKeys: [result copy],NSForegroundColorAttributeName, nil]; } [UIView animateWithDuration:DKNightVersionAnimationDuration animations:^{
pragma clang diagnostic push
pragma clang diagnostic ignored "-Warc-performSelector-leaks"
pragma clang diagnostic pop
}