是否可以强制属性设置器中的值?
我想要的是覆盖 UINavigationBar twinColor 设置器并强制使用默认颜色。下面是我的代码(当然失败了)。有办法让它发挥作用吗?
@implementation UINavigationBar (UINavigationBarCategory)
- (void)setTintColor:(UIColor *)tint {
self.tintColor = [UIColor greenColor];
}
@end
What I want is to override UINavigationBar tintColor setter and force default color to it. Bellow is my code (which of course fails). Is there a way to make it work?
@implementation UINavigationBar (UINavigationBarCategory)
- (void)setTintColor:(UIColor *)tint {
self.tintColor = [UIColor greenColor];
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(我在这里使用
property
作为通用术语,在您的示例中,它是tintColor
的替代品)我认为您不能使用
self .property =
语法,用于在setProperty:
方法中进行赋值。self.property
只是[self setProperty:]
的别名,它将递归调用自身。你必须做这样的事情:
我仍然不能 100% 确定你想做的事情会起作用,但前面的只是一个开始。
(I'm using
property
as a generic term here, in your example it's a stand-in fortintColor
)I don't think you can use the
self.property =
syntax for assignment inside asetProperty:
method.self.property
is just an alias for[self setProperty:<value>]
and it will recursively call itself.You'll have to do something like this:
I'm still not 100% sure what you're trying to do will work, but the preceding is a start.
如果你想强制导航栏的默认颜色,为什么不在视图控制器的 viewDidLoad/viewDidAppear 中设置色调颜色?
If you want to force a default color of a NavigationBar, why don't you set the tint color in viewDidLoad/viewDidAppear of your view controller??