菜鸟教程小白 发表于 2022-12-13 06:00:49

iOS 7 弹出框覆盖进度条和 uibarbuttonItem 色调颜色


                                            <p><p>我的导航栏有问题。
<code>UIBarButtonItem</code> <code>tintColor</code> 是橙色的,但是当我呈现 popover 时,<code>barButtonItem</code> <code>tintColor</code> 变为 lightGray。导航栏色调颜色为白色。我需要在弹出框出现后留下橙色。
有人能帮我吗?谢谢!</p>

<p>编辑 1</p>

<p>我制作了可选择的 barButtonItem,并且我有 UIBarButtonItem 的子类:</p>

<pre><code>-(void)setSelected:(BOOL)selected {
    _selected = selected;
    if (selected) {
      self.tintColor = self.selectedColor;
    } else {
      self.tintColor = self.defaultColor;
    }
}

-(id)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action defaultColor:(UIColor *)defaultColor {
    self = ;
    if (self) {
      self.tintColor = defaultColor;
    }
    return self;
}

-(id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action defaultColor:(UIColor *)defaultColor {
    self = ;
    if (self) {
      self.tintColor = defaultColor;
    }
    return self;
}
</code></pre>

<p>编辑 2</p>

<p>感谢 Warren Burton 的回答,解决方案是:</p>

<pre><code>self.navigationController.navigationBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>此行为是 iOS 7 "Normal"。它告诉您的用户该按钮当前不是您的事件 UI 的一部分。 </p>

<p>如果你想绕过这个常规约定,你可以继承 UIBarButtonItem 并覆盖</p>

<p><code>- (void)tintColorDidChange</code></p>

<p>只留下一个空的实现。 </p>

<pre><code>- (void)tintColorDidChange {
   //nothing to see here, move along
}
</code></pre>

<p>当弹出框呈现时,呈现 View 进入 tintMode <code>UIViewTintAdjustmentModeDimmed</code> 因此即使您提供另一种颜色,该颜色也会被系统变灰(不饱和?)。 </p>

<p>这就是为什么你需要覆盖 <code>tintColorDidChange</code> 来阻止这种情况发生。</p>

<p>来自文档...</p>

<blockquote>
<p>When this property’s value is UIViewTintAdjustmentModeDimmed, the
value of the tintColor property is modified to provide a dimmed
appearance.</p>
</blockquote></p>
                                   
                                                <p style="font-size: 20px;">关于iOS 7 弹出框覆盖进度条和 uibarbuttonItem 色调颜色,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/21280651/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/21280651/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS 7 弹出框覆盖进度条和 uibarbuttonItem 色调颜色